Intuition
When setting up a new Drupal site, one of the key tasks is configuring the theme to suit your design and content needs. Paragraphs, a popular module in Drupal, allows you to create flexible and reusable content components, and is used extensively in many of the projects.
Althought we could adhere the look of the pargraph through preserving the paragraph--xxyyzz.html.twig
file, the configuration including ranging from the machine name, help text, fields, views, are not captured in the paragraph--xxyyzz.html.twig
file, and require some effort to setup from the Drupal backend. Hence if we could include those as a part of the sub-theme’s configuration to be installed with the theme, this could save the devs heaps of time.
Steps to Export Paragraph Configurations
Method 1: Drush Command
First export of the Drupal configuration via
drush config:export
to save the status before the changeThen configure your new paragraph type, add fields, configure views, …
Second export of the configuration via the same command to save the status after the change happens
Then look carefully to identify which configurations are relevant to the paragraph change you’ve made (for the screenshot example, only the configuration containing the keyword
paragraph
andcard
are relevant)Use
cp
command to copy the releevantyml
files to the theme’sconfig/install
folder. The-i
flag will prompt user when attempting to override an existing file (example of such command could be found here: exmaple_cp_script.txt)
(*if you are familiar with the names of the yml configuration files, you could skip to the last step)
Method2: GUI Interface
- Navigate to Configuration > Configuration Synchronization > Export.
- Select Single Item and choose from the configuration type. (You’ll need to export Paragraph, Field, View one by one)
- Copy the configuration content and save to files with the instructed filename.
Outcome
From the below video, the importing the configuration files in theme_name/config/install
file is automatically performed as a part of the installation process of the subtheme. As a result the two paragraph types card
and toc
are automatically created.