Skip to main content
Image
banner1.jpg

Writing a Drupal 8 Installation Profile

article publisher

Bikash

Drupal

An installation profile is a tailored package which makes it possible for the user to set up complex sites using relatively fewer steps. An installation profile, let's say for news sites, will include features and modules for user registration, news submission, forums, everything that a news website need. Here, you can clearly see the convenience an installation profile would provide. 

Let's see how we can write an installation profile. It is mandatory for a Drupal installation profile to include a profilename.info.yml and may also include the below-listed files or folders:

  • profilename.profile
  • profilename.install file
  • config folder
  • translations folder

As an example, we will be following the standard installation provided with vanilla Drupal.

Vanilla Drupal includes two installation profiles viz., 

  • Standard
  • Minimal

Both of these profiles come bundled with various modules to satisfy different user requirements. However, it does not guarantee that the default installation will solve each and every user's needs. Yes, a user can install modules to solve compatibility issues but picking individual modules from among 38000+ modules is going to be tedious and if he/she is a newbie then things will get chaotic.

The standard.info.yml (profilename.info.yml) file should follow the structure as below:

standard.info.yml file.
The standard.info.yml file.

Provide a suitable name as because profiles are like modules and need to constitute valid PHP function name. 
Example, if the profile is for Acme starter kit valid profile machine names would be

  • acme_starter_kit
  • acme_starter
  • acme_starter_profile
  • acme_kit

The following would be invalid

  • acme-starter-kit
  • acme-kit

The dependencies and theme section contains the modules and themes that would be installed in the standard profile is chosen. 

>>standard.install (profilename.install) 

This file defines the permission of the administrator, placement of the contact link, default permissions for users, creates shortcuts, nodes etc.
 
A specimen of the standard profile has been displayed below.

The standard.install file.

>>standard.links.menu.yml(profilename.links.menu.yml)

The standard.links.menu. yml file contents.
The standard.links.menu. yml file contents.

This file is used to create hierarchical menu links. Additional custom links can also be added.

After successful completion of the above steps, we shift our attention to the Config Folder where we can copy contents from an already installed profile and pasting it in the config/install folder of our profile.

Now, we navigate to <project-root>/core/config and copy all the themes and modules listed in the core.extension.yml onto our profile's info file. Do note that the themes listed will be installed but none will be activated by default. To do so we need to copy system.theme.yml and paste it in <project-root>\core\profiles\standard\config\install

highlighted system.theme.yml file.
Highlighted system.theme.yml file.

Next, we need to remove all UUIDs (Universally Unique Identifier) and default_config_hash to avoid conflicts. It can be easily executed using command lines as mentioned below.

For Windows:

find /path/to/PROFILE_NAME/config/install/ -type f -exec sed -i -e '/^uuid: /d' {} \;
find /path/to/PROFILE_NAME/config/install/ -type f -exec sed -i -e '/_core/,+1d' {} \;

For Mac OSX:

find /path/to/PROFILE_NAME/config/install/ -type f -exec sed -i '' '/^uuid: /d' {} \;
find /path/to/PROFILE_NAME/config/install/ -type f -exec sed -i '' '/_core/{N;d;}' {} \;

>>Translations Folder:

This folder would contain all the translation options for the profile which can be included by having a file as such:

drupal/de/drupal-8.0..de.po

Now that we have all the necessary files, let's look at how we can package it into a Drupal.org-specific file

>>Drush Make File:

Drush make basically creates a drush-org.make file which contains all the latest releases of all modules/themes included in the profile.

$/drush generate-makefile drupal-org.make

>>Verify drush-org.make file :

Required module https://www.drupal.org/project/drupalorg_drush.
Verifying the make file is important to check if it is Drupal.org-compatible by typing in the following Drush command.

drush verify-makefile

A successful operation would return the following:

Starting Drupal.org core makefile validation, please wait                   [ok]
Makefile drupal-org-core.make passed.                                                [ok]

However, errors might occur and to proceed to the next step, all errors detected in this process needs to be neutralized.
The link below lists some common errors and their solutions.

https://www.drupal.org/node/1432190

Following the steps above we can create an installation profile fit to suit our requirements and chill out while the profile installs itself on our system without worrying about the need to install modules, dependencies etc.

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

SDC: Integrating Storybook & Single Directory Component

Integrating SDC With Storybook OpenSense Labs

Today, we will talk about about Drupal Single Directory Components or SDC and Storybook. Single Directory Components in Drupal allows you…

RFP: How To Create An RFP For Open Source Solutions?

RFP OpenSense Labs

A good Request for Proposals (RFP) or Call for Proposals (CFP) clearly states the goals and expectations of your project and sets the…

Drupal 7 End Of Life: Top Reasons You Should Migrate To Drupal 10

Drupal 7 End Of Life Cover Image OpenSense Labs

Drupal 10 was released in December 2022 and ever since, the community has been pushing its users to do Drupal 7 to 10 migration. As per…