Better Practice, Dec. 2018

(singke) #1
http://www.phparch.com \ December 2018 \ 11

The Flexibility of Drupal 8

to confirm the changes. As seen in Figure 4, end users now
see the updated item with the new title.


Modules


Central to Drupal is the ability to add new functionality by
installing modules. A module is a self-contained set of code
that enhances, alters, or adds functionality. Since Drupal is an
open-source framework, anyone can create a module for it.


Modules are available for free to download on Drupal.org^2.
Over 30,000 community-created modules are currently avail-
able for use. This large number means it is likely a module or
set of modules exists for any customization needed.
Using community modules to solve a need does come with
limitations. The primary constraint is the lack of control over
a module’s functionality. Since a module is a self-contained
set of functionality, a user cannot change how a module
works or what functionality it executes. Also, a module may
provide a solution to complete a specific task, while simul-
taneously altering existing functionality or adding new and
unwanted changes. A module may solve a need in a different


2 Drupal.org: https://drupal.org


way than expected, requiring re-work of other parts of the
implementation.

Installing Modules
To use community modules, they must be installed on the
Drupal instance. Drupal provides many methods for install-
ing modules. The preferred method depends on the structure
of the implementation and skillset of the team performing
the installation. The Drupal documentation has instructions
for the different ways available to install a module^3.
Regardless of the method (composer, drush, download-
ing), community modules are always added to the /modules/
contrib/ directory. Once added to the codebase, modules
need to be enabled. Like installation, enabling a module
has many methods. The simplest way to enable a module is
through the Drupal Admin interface.

Changing a Menu Item Using a Module
Searching drupal.org for the term “menu alter” returns
many results. One of the results is the module Menu Link
Attributes. The module’s description indicates that it provides
the needed functionality. Downloading the module and plac-
ing it in /modules/contrib/ makes it available for use on the
Drupal instance.
The admin toolbar is used to navigate to the module admin
page by clicking on Manage and then Extend. This page
displays a list of all modules available in the Drupal instance.
Searching for the term “menu” in the filter field helps find the
new module, as shown in Figure 5.
Checking the checkbox next to the module name marks it
for installation. At the bottom of the page, the Install button is
clicked to submit the form. Drupal then enables the module
and adds the new functionality. The newly enabled module
has updated the Edit menu link form to include an Attributes
section, as shown in Figure 6.

3 install a module: https://phpa.me/d8-install-modules

Figure 3

Figure 4 Figure 5
Free download pdf