Last active
November 19, 2021 13:35
-
-
Save levmyshkin/f06e18f2e762b933a98180a8825fddfa to your computer and use it in GitHub Desktop.
Create a custom Drupal module with route and controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: DrupalBook | |
description: Custom module for learning Drupal | |
type: module | |
core: 8.x | |
core_version_requirement: ^8 || ^9 | |
package: DrupalBook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drupalbook.first_page: | |
path: '/first-page' | |
defaults: | |
_controller: '\Drupal\drupalbook\Controller\FirstPageController::content' | |
_title: 'Hello World!' | |
requirements: | |
_permission: 'access content' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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