Skip to content

Instantly share code, notes, and snippets.

@levmyshkin
Last active November 19, 2021 13:35
Show Gist options
  • Save levmyshkin/f06e18f2e762b933a98180a8825fddfa to your computer and use it in GitHub Desktop.
Save levmyshkin/f06e18f2e762b933a98180a8825fddfa to your computer and use it in GitHub Desktop.
Create a custom Drupal module with route and controller
name: DrupalBook
description: Custom module for learning Drupal
type: module
core: 8.x
core_version_requirement: ^8 || ^9
package: DrupalBook
drupalbook.first_page:
path: '/first-page'
defaults:
_controller: '\Drupal\drupalbook\Controller\FirstPageController::content'
_title: 'Hello World!'
requirements:
_permission: 'access content'
<?php
/**
* @file /modules/custom/drupalbook/src/Controller/FirstPageController.php
*/
namespace Drupal\drupalbook\Controller;
/**
* Provides route responses for the DrupalBook module.
*/
class FirstPageController {
/**
* Returns a simple page.
*
* @return array
* A simple renderable array.
*/
public function content() {
$element = array(
'#markup' => 'Hello World!',
);
return $element;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment