Created
September 30, 2014 12:04
-
-
Save rakeshjames/e2588a1d384b5d33f89a to your computer and use it in GitHub Desktop.
Drupal 8 Custom module example
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: Drupal 8 custom module example | |
type: module | |
description: 'Example for Drupal 8 modules.' | |
package: Custom | |
version: 8.x | |
core: 8.x |
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 | |
* Example custom module for Drupal 8. | |
* @author Rakesh James | |
*/ | |
/** | |
* Implementing hook_menu(). | |
*/ | |
function example_menu() { | |
// The paths given here need to match the ones in example.routing.yml exactly. | |
$items['/mypage/page'] = array( | |
'title' => 'First page', | |
'description' => 'This is a example page.', | |
// The name of the route from example.routing.yml | |
'route' => 'example.my_page', | |
); | |
return $items; | |
} |
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
example.my_page: | |
path: '/mypage/page' | |
defaults: | |
_content: '\Drupal\example\Controller\ExampleController::myPage' | |
_title: 'My first page in Drupal8' | |
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 | |
* @author Rakesh James | |
* Contains \Drupal\example\Controller\ExampleController. | |
* Please place this file under your example(module_root_folder)/src/Controller/ | |
*/ | |
namespace Drupal\example\Controller; | |
/** | |
* Provides route responses for the Example module. | |
*/ | |
class ExampleController { | |
/** | |
* Returns a simple page. | |
* | |
* @return array | |
* A simple renderable array. | |
*/ | |
public function myPage() { | |
$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