Folkbot Drupal 8 Distribution Referencing Standard & Lightning

Folkbot Drupal 8 Distribution

In Part 1 we set-up a Drupal 8 default Git repository with Drupal.org as upstream and Gitlab as our origin for continuous integration.

Drupal 8 Installation Profiles

Drupal.org has had a face-lift and we hit the spanking new docs

Lightning & Standard Distribution as Reference

https://www.drupal.org/u/brantwynn has created the excellent Lightning Distribution as a kind of reference and best practice Drupal 8 site while working for Acquia, lets use that as a reference.

Notice the difference between downloading the code vs downloading a tar or zip. The tar/zip is an entire working codebase, whereas the code via git needs to be built with composer and Drush Make and the D8 build tool-chain.

Lets keep it simple and download the tar.gz.

Also, lets rename the folder according to Lightning conventions

Our new folder name is folkbot-8.2-dev-0.01, we can keep the gitlab repo the same and use branches and tags as needed depending on how we work with dev/test/live.

Choose a Machine Name

We are calling this machine name folkbot

[code lang=text]
cd /home/devekko/Projects/Folkbot/drupal8/folkbot-8.2-dev-0.01/profiles/
vi folkbot.info.yml
[/code]

inside the file we add meta information and also modules we require our custom module called folkbot and our theme folkbot which will be based on the Bootstrap theme

[code lang=text]
name: Folkbot
type: profile
description: 'Folkbot – automation of the people, by the people, for the people'
core: 8.x

# Optional: Declare your installation profile as a distribution
# This will make the installer auto-select this installation profile.
# The distribution_name property is used in the installer and other places as
# a label for the software being installed.
distribution:
# name: Folkbot TODO make a Distribution

# Required modules
dependencies:
# CORE modules
– block
– block_content
– breakpoint
– ckeditor
– color
– config
– comment
– contextual
– contact
– contact_storage
– datetime
– diff
– dblog
– editor
– entity_reference
– field_ui
– file
– help
– history
– image
– options
– menu_link_content
– path
– quickedit
– rdf
– search
– shortcut
– toolbar
– taxonomy
– views
– views_ui
# CONTRIB modules
– metatag
– node
– search_api_db
– bootstrap_layouts
# CUSTOM modules
– folkbot

themes:
# CONTRIB theme
– bootstrap
# CUSTOM theme
– folkbot
# CORE themes
– bartik
– seven
[/code]

next we add an .install file

[code lang=text]
vi folkbot.install
[/code]

we use the default basic script snippet and call the core profile buried away deeper in core, and then we take some basic installation functions from Lightning, such as setting logo, homepage, admin user etc.

Looking at the Drupal Core Standard installation we also see we have repeated installation functions, we remove those and we have code below

[code lang=text]
<!–?php /** * @file * Install, update and uninstall functions for the Folkbot install profile. */ use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\field\Entity\FieldConfig; use Drupal\node\Entity\NodeType; use Drupal\user\Entity\User; use Drupal\user\RoleInterface; /** * Implements hook_install(). * * Perform actions to set up the site for this profile. * * @see system_install() */ function folkbot_install() { // First, do everything in standard profile. include_once DRUPAL_ROOT . '/core/profiles/standard/standard.install'; standard_install(); // Restrict user registration to admin role creation. \Drupal::configFactory() ->getEditable('user.settings')<br ?–> ->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)
->save(TRUE);

// Set the default and admin theme.
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'folkbot')
->set('admin', 'seven')
->save(TRUE);

// Set the path to the logo, favicon and README file based on install
// directory.
$folkbot_path = drupal_get_path('profile', 'folkbot');
\Drupal::configFactory()
->getEditable('system.theme.global')
->set('logo', [
'path' => $folkbot_path . '/folkbot.png',
'url' => '',
'use_default' => FALSE,
])
->set('favicon', [
'mimetype' => 'image/vnd.microsoft.icon',
'path' => $folkbot_path . '/favicon.ico',
'url' => '',
'use_default' => FALSE,
])
->save(TRUE);
}
[/code]

we see a bunch of profiles in core

[code lang=text]
ls -alh /home/devekko/Projects/Folkbot/drupal8/folkbot-8.2-dev-0.01/core/profiles
total 40K
drwxr-xr-x 10 devekko devekko 4.0K Feb 9 14:39 .
drwxr-xr-x 12 devekko devekko 4.0K Feb 9 14:39 ..
drwxr-xr-x 4 devekko devekko 4.0K Feb 9 14:39 minimal
drwxr-xr-x 4 devekko devekko 4.0K Feb 9 14:39 standard
drwxr-xr-x 4 devekko devekko 4.0K Feb 9 14:39 testing
drwxr-xr-x 2 devekko devekko 4.0K Feb 9 14:39 testing_config_import
drwxr-xr-x 3 devekko devekko 4.0K Feb 9 14:39 testing_config_overrides
drwxr-xr-x 2 devekko devekko 4.0K Feb 9 14:39 testing_missing_dependencies
drwxr-xr-x 3 devekko devekko 4.0K Feb 9 14:39 testing_multilingual
drwxr-xr-x 3 devekko devekko 4.0K Feb 9 14:39 testing_multilingual_with_english

[/code]

and standard profile

[code lang=text]
tree /home/devekko/Projects/Folkbot/drupal8/folkbot-8.2-dev-0.01/core/profiles/standard

home/devekko/Projects/Folkbot/drupal8/folkbot-8.2-dev-0.01/core/profiles/standard
├── config
│   ├── install
│   │   ├── automated_cron.settings.yml
│   │   ├── block.block.bartik_account_menu.yml
│   │   ├── block.block.bartik_branding.yml
│   │   ├── block.block.bartik_breadcrumbs.yml
│   │   ├── block.block.bartik_content.yml
│   │   ├── block.block.bartik_footer.yml
│   │   ├── block.block.bartik_help.yml
│   │   ├── block.block.bartik_local_actions.yml
│   │   ├── block.block.bartik_local_tasks.yml
│   │   ├── block.block.bartik_main_menu.yml
│   │   ├── block.block.bartik_messages.yml
│   │   ├── block.block.bartik_page_title.yml
│   │   ├── block.block.bartik_powered.yml
│   │   ├── block.block.bartik_search.yml
│   │   ├── block.block.bartik_tools.yml
│   │   ├── block.block.seven_breadcrumbs.yml
│   │   ├── block.block.seven_content.yml
│   │   ├── block.block.seven_help.yml
│   │   ├── block.block.seven_local_actions.yml
│   │   ├── block.block.seven_login.yml
│   │   ├── block.block.seven_messages.yml
│   │   ├── block.block.seven_page_title.yml
│   │   ├── block.block.seven_primary_local_tasks.yml
│   │   ├── block.block.seven_secondary_local_tasks.yml
│   │   ├── block_content.type.basic.yml
│   │   ├── comment.type.comment.yml
│   │   ├── contact.form.feedback.yml
│   │   ├── core.base_field_override.node.page.promote.yml
│   │   ├── core.entity_form_display.block_content.basic.default.yml
│   │   ├── core.entity_form_display.comment.comment.default.yml
│   │   ├── core.entity_form_display.node.article.default.yml
│   │   ├── core.entity_form_display.node.page.default.yml
│   │   ├── core.entity_form_display.user.user.default.yml
│   │   ├── core.entity_view_display.block_content.basic.default.yml
│   │   ├── core.entity_view_display.comment.comment.default.yml
│   │   ├── core.entity_view_display.node.article.default.yml
│   │   ├── core.entity_view_display.node.article.rss.yml
│   │   ├── core.entity_view_display.node.article.teaser.yml
│   │   ├── core.entity_view_display.node.page.default.yml
│   │   ├── core.entity_view_display.node.page.teaser.yml
│   │   ├── core.entity_view_display.user.user.compact.yml
│   │   ├── core.entity_view_display.user.user.default.yml
│   │   ├── editor.editor.basic_html.yml
│   │   ├── editor.editor.full_html.yml
│   │   ├── field.field.block_content.basic.body.yml
│   │   ├── field.field.comment.comment.comment_body.yml
│   │   ├── field.field.node.article.body.yml
│   │   ├── field.field.node.article.comment.yml
│   │   ├── field.field.node.article.field_image.yml
│   │   ├── field.field.node.article.field_tags.yml
│   │   ├── field.field.node.page.body.yml
│   │   ├── field.field.user.user.user_picture.yml
│   │   ├── field.storage.node.comment.yml
│   │   ├── field.storage.node.field_image.yml
│   │   ├── field.storage.node.field_tags.yml
│   │   ├── field.storage.user.user_picture.yml
│   │   ├── filter.format.basic_html.yml
│   │   ├── filter.format.full_html.yml
│   │   ├── filter.format.restricted_html.yml
│   │   ├── node.type.article.yml
│   │   ├── node.type.page.yml
│   │   ├── rdf.mapping.comment.comment.yml
│   │   ├── rdf.mapping.node.article.yml
│   │   ├── rdf.mapping.node.page.yml
│   │   ├── rdf.mapping.taxonomy_term.tags.yml
│   │   ├── system.cron.yml
│   │   ├── system.theme.yml
│   │   ├── taxonomy.vocabulary.tags.yml
│   │   └── user.role.administrator.yml
│   └── optional
│   ├── image.style.max_1300x1300.yml
│   ├── image.style.max_2600x2600.yml
│   ├── image.style.max_325x325.yml
│   ├── image.style.max_650x650.yml
│   ├── responsive_image.styles.narrow.yml
│   └── responsive_image.styles.wide.yml
├── standard.info.yml
├── standard.install
├── standard.links.menu.yml
├── standard.profile
└── tests
└── src
└── Functional
└── StandardTest.php

6 directories, 80 files

[/code]

vs Lightning, a more sophisticated distro

[code lang=text]
tree /home/devekko/Projects/lightning-8.x-2.03/profiles/lightning
1291 directories, 3102 files
[/code]

we create a folkbot.profile

[code lang=text]
vi folkbot.profile
<!–?php <br ?–> /**
* @file
* Enables modules and site configuration for a standard site installation.
*/

// Add any custom code here like hook implementations.
[/code]

Now when we visit the local dev site in our browser we can install and choose our partly built installation profile

Choose language | Drupal - Google Chrome_001
Choose language | Drupal – Google Chrome_001

and choose profile

Select an installation profile | Drupal - Google Chrome_002
Select an installation profile | Drupal – Google Chrome_002

we make the files directory

[code lang=text]
mkdir sites/default/files
[/code]

make it writeable with permissions and groups

[code lang=text]
sudo chmod -R 775 sites/default/files
sudo chown -R $USER:www-data sites/default/files
[/code]

copy the settings file

cp -ar /var/www/folkbot_drupal8/sites/default/default.settings.php /var/www/folkbot_drupal8/sites/default/settings.php

make it writeable with permissions as above

[code lang=text]
sudo chown $USER:www-data /var/www/folkbot_drupal8/sites/default/settings.php
sudo chmod 775 /var/www/folkbot_drupal8/sites/default/settings.php
[/code]

and we need to create a gitignore and make sure our settings isn’t in our git repo, a good reference is this repo with many specific gitgnores

we need to now install Drush and download the missing modules from the docs

[code lang=text]
[email protected]:/var/www/folkbot_drupal8⟫ # Download latest stable release using the code below or browse to github.com/drush-ops/drush/[email protected]:/var/www/folkbot_drupal8⟫ php -r "readfile('https://s3.amazonaws.com/files.drush.org/drush.phar');" > drush
[email protected]:/var/www/folkbot_drupal8⟫ # Or use our upcoming release: php -r "readfile('https://s3.amazonaws.com/files.drush.org/drush-unstable.phar');" > drush
[email protected]:/var/www/folkbot_drupal8⟫
[email protected]:/var/www/folkbot_drupal8⟫ # Test your install.
[email protected]:/var/www/folkbot_drupal8⟫ php drush core-status
Drupal version : 8.2.6
Site URI : http://default
PHP configuration : /etc/php/7.0/cli/php.ini
PHP OS : Linux
Drush script : /var/www/folkbot_drupal8/drush
Drush version : 8.1.9
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : /var/www/folkbot_drupal8
Drupal Settings File : sites/default/settings.php
Site path : sites/default

[email protected]:/var/www/folkbot_drupal8⟫
[email protected]:/var/www/folkbot_drupal8⟫ # Make `drush` executable as a command from anywhere. Destination can be anywhere on $PATH.
[email protected]:/var/www/folkbot_drupal8⟫ chmod +x drush
[email protected]:/var/www/folkbot_drupal8⟫ sudo mv drush /usr/local/bin
[email protected]:/var/www/folkbot_drupal8⟫
[email protected]:/var/www/folkbot_drupal8⟫ # Optional. Enrich the bash startup file with completion and aliases.
[email protected]:/var/www/folkbot_drupal8⟫ drush init
Copied example Drush configuration file to /home/devekko/.drush/drushrc.php [ok]
Copied example Drush bash configuration file to /home/devekko/.drush/drush.bashrc [ok]
Copied Drush completion file to /home/devekko/.drush/drush.complete.sh [ok]
Copied example Drush prompt file to /home/devekko/.drush/drush.prompt.sh [ok]
# Include Drush bash customizations.
if [ -f "/home/devekko/.drush/drush.bashrc" ] ; then
source /home/devekko/.drush/drush.bashrc
fi

# Include Drush completion.
if [ -f "/home/devekko/.drush/drush.complete.sh" ] ; then
source /home/devekko/.drush/drush.complete.sh
fi

# Include Drush prompt customizations.
if [ -f "/home/devekko/.drush/drush.prompt.sh" ] ; then
source /home/devekko/.drush/drush.prompt.sh
fi

Append the above code to /home/devekko/.bashrc? (y/n): y
Updated bash configuration file /home/devekko/.bashrc [ok]
Start a new shell in order to experience the improvements (e.g. `bash`). [ok]
[/code]

we can drush dl modules now and copy them to the profiles/modules folder, from help

[code lang=text]
drush dl –help | grep "destination"
If no –destination is provided, then destination depends on the project type:
–destination= Path to which the project will be copied. If you're providing a relative path, note it is relative to the
–destination is also present this option will be ignored.
[/code]

install modules

[code lang=text]
drush dl metatag –destination=profiles/folkbot/modules
Project metatag (8.x-1.0) downloaded to /var/www/folkbot_drupal8/profiles/folkbot/modules/metatag. [success]
Project metatag contains 14 modules: metatag_dc_advanced, metatag_dc, metatag_hreflang, metatag_app_links, metatag_mobile, metatag_facebook, metatag_twitter_cards, metatag_open_graph, metatag_open_graph_products, metatag_google_cse, metatag_verification, metatag_google_plus, metatag_favicons, metatag.
[/code]

lets add Bootstrap base theme

[code lang=text]
drush dl bootstrap –destination=profiles/folkbot/themes
The directory profiles/folkbot/themes does not exist.
Would you like to create it? (y/n): y
Project bootstrap (8.x-3.1) downloaded to /var/www/folkbot_drupal8/profiles/folkbot/themes/bootstrap. [success]
[/code]

and token module

[code lang=text]
drush dl token –destination=profiles/folkbot/modules
Project token (8.x-1.0-rc1) downloaded to /var/www/folkbot_drupal8/profiles/folkbot/modules/token.
[/code]

we now get a prompt to change settings.php back to a more secure read only setting

[code lang=text]
sudo chmod 555 /var/www/folkbot_drupal8/sites/default/settings.php
[/code]

We now see a site after we manually change to Bootstrap theme

Folkbot Drupal 8 Distribution
Folkbot Drupal 8 Distribution

We will build the Folkbot theme next

In part 3 we make a custom theme, part 4 a custom module for a rest API.

Folkbot Drupal 8 Distribution Part 1 – Code Setup

Folk Bot Drupal 8

We are going to build a Folkbot Drupal 8 Distribution, Profile, Module, Theme.

This will connect with the central proprietary www.Folkbot.com and also other Folkbot servers, self hosted, forks etc in the federation.

Or that is the plan anyways.

Drupal 8 Installation Profiles

Drupal.org has had a face-lift and we hit the spanking new docs

Download Drupal 8

It’s tempting to set-up a GIT upstream right now from Drupal.org, lets live dangerously

mkdir -p ~/Projects/Folkbot/drupal8
cd ~/Projects/Folkbot/drupal8

note, we are nesting a bit deeper so I can put other working folder and files above the repo as needed

git clone --branch 8.2.x https://git.drupal.org/project/drupal.git folkbot_drupal8
cd folkbot_drupal8

I am adding the Gitlab remote for Folkbot

git remote add gitlab_com [email protected]:folkbot/folkbot_drupal8.git

and lets remove origin so we dont accidentally pull from it

git remote remove origin 

and we can add it again as drupal_org

git remote add drupal_org https://git.drupal.org/project/drupal.git

its a nice thing to have two remotes, one upstream from source, and another our customizations

[email protected]:~/Projects/Folkbot/drupal8/folkbot_drupal8⟫ git remote -v
drupal_org      https://git.drupal.org/project/drupal.git (fetch)
drupal_org      https://git.drupal.org/project/drupal.git (push)
gitlab_com      [email protected]:folkbot/folkbot_drupal8.git (fetch)
gitlab_com      [email protected]:folkbot/folkbot_drupal8.git (push)

lets make the branch 8.2.x our master branch, we can make feature branches and tags for our work later, we want to be able to keep drupal.org upstream branches separate from our own work

git checkout -b master
git status
On branch master
nothing to commit, working tree clean

now lets modify create a FOLKBOT.md

touch ~/FOLKBOT.md
git commit -am "FolkBot docs"

and now we can push to Gitlab

git push -u gitlab_com master