Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Drupal 8 Configuration Management

You're reading from  Drupal 8 Configuration Management

Product type Book
Published in Mar 2015
Publisher
ISBN-13 9781783985203
Pages 148 pages
Edition 1st Edition
Languages
Concepts

Table of Contents (16) Chapters

Drupal 8 Configuration Management
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
1. Understanding Configuration Management 2. Configuration Management for Administrators 3. Drupal 8's Take on Configuration Management 4. The Configuration Management API 5. The Anatomy of Schema Files 6. Adding Configuration Management to Your Module 7. Upgrading Your Drupal 7 Variables to the Drupal 8 Configuration 8. Managing Configuration for Multilingual Websites 9. Useful Tools and Getting Help Index

Chapter 6. Adding Configuration Management to Your Module

After we learned how to access configuration objects and how schema files are structured in previous chapters, you will surely want to know how to get all this fancy stuff into your shiny new module for Drupal 8.

We will learn how to include the default configuration in custom modules, how to define and use your own configuration, and how to create configuration forms.

Default configuration


Let's start with a simple task and add some default configuration to our example module.

In Drupal 7, you have to use custom code to create and update the default configuration, such as content types, views, or field configurations. Many people also use the great Features module that provides some handy functions to manage default configuration easily.

Drupal 8 uses the .yml files we talked about extensively in previous chapters to store information about the default configuration. The Configuration Management system itself takes care of creating and managing the default configuration, so we can focus on writing its definition rather than creating the functions for management.

An example

Let's add a custom vocabulary to our site and define the term container and its configuration in the example module we used in the previous chapters. The vocabulary should be named Category and have the internal identifier cm_example_category (this is the machine-readable name). For the...

Defining and using your own configuration


Sometimes, including default configuration objects defined by other modules is not enough, and you may want to define your own configuration. As with many other parts of the Configuration Management in Drupal 8, this is not very complicated.

Setting your configuration file

Configuration files for configuration objects defined by a module reside in the config/install subdirectory of this module. In our example, this is /modules/custom/cm_example/config/install.

Tip

We put our example module in a directory named custom inside the modules directory to separate contributed modules downloaded from https://drupal.org from custom modules. This is a well-known best practice when creating sites to keep your modules organized.

In Chapter 3, Drupal 8's take on Configuration Management, we mentioned the naming conventions of configuration files. As said before, simple module settings should go into a file named <module name>.settings.yml; thus, in our case...

Summary


As you can see, it is not very complicated to add a default configuration to your Drupal 8 module and to create a custom form for your configuration.

Drupal 8 provides you with powerful tools to define the form and create the required menu items, so you can focus on the form itself and give your users a good user experience.

Having to upgrade a configuration defined in previous versions, though, is not as simple. In the next chapter, we will describe how to upgrade your variables from older versions of Drupal to make them available with the new Configuration Management system.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Drupal 8 Configuration Management
Published in: Mar 2015 Publisher: ISBN-13: 9781783985203
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}