Ultimate Guide To Drupal 8.6
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Getting OOP-y with It<br />
Let’s look at a few code samples to illustrate <strong>Drupal</strong> 8’s architecture in action.<br />
Registering a Module<br />
<strong>Drupal</strong>'s functionality is extended through the use of modules. Step 0 to writing a module is describing some metadata in order to register it in the system.<br />
This is done in an "info" file, which are simple YAML files.<br />
example.yaml.info<br />
name: Example<br />
type: module<br />
description: 'An example module.'<br />
core: 8.x<br />
dependencies:<br />
- user<br />
Defining a URL and content<br />
A common thing modules do is expose URLs that produce some sort of output. This is done in two parts: a routing.yml file (which utilizes the Symfony<br />
Routing System to define "route" (URL) metadata) and a "controller" class (as in the standard model-view-controller pattern):<br />
Defining a URL and content<br />
A common thing modules do is expose URLs that produce some sort of output. This is done in two parts: a routing.yml file (which utilizes the Symfony<br />
Routing System to define "route" (URL) metadata) and a "controller" class (as in the standard model-view-controller pattern):<br />
example.routing.yml<br />
example.hello:<br />
path: '/hello'<br />
defaults:<br />
_controller: '\<strong>Drupal</strong>\example\Controller\HelloController::hello'<br />
requirements:<br />
_permission: 'access content'<br />
44