Composer

Rating

You need composer to run some Drupal 8 modules. For some people this is scary... Ik have hundreds of students who chose a CMS in order not to use code... Now this seems far away.

I have the intention to explain the basics of composer, just to install what you need, not more then that.. I know the drushers will laugh..

What does Composer?

It can install modules and their dependecies. Sometimes in the Vendor folder, files are added. It must be possible to add the third party libraries too. (colorbox, views slideshow...) But this seems so complexe, on this moment,  that i do it faster with FTP.

First you need SSH access en a Linux program (Putty) to access the server (see contribution about that)

Drupal8_002025.png

With dir you see the folders and files, with cd you go to a folder. With cd ../ you go back. These are Linux commands.

Go to the right folder (public_html here). Copy and paste. Paste with richt click. Putty does not accept Ctrl+V

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

From now on every command needs to start with php composer.phar. 

You can change this to composer:

mv composer.phar /usr/local/bin/composer

Ik keep it simple... So from now on every time you see composer write php composer.phar!

Type this composer code to say that all information has to be gathered from drupal.org. This is important!

composer config repositories.drupal composer https://packages.drupal.org/8

Let us install a module: admin toolbar. composer require drupal/admin_toolbar  and enter. Done. Set the module active manually.. Drushers will do it their way..

Drupal8_002034.png

The power of Composer shows if modules are installed with dependencies. Swiftmailer is such one. It is impossible to install this module without composer.

 composer require drupal/swiftmailer .

You will see that the dependencies are installed. Activate en done. Look at them. Some are from Drupal, others aren't!


Drupal8_002029.png

Activate.

Drupal8_002031.png

Another example.. The address module is a composite field module. Depending on the country other fields are displayed. There are 200 countries available...

composer require drupal/address

See the dependencies.


Drupal8_002033.png

What has happened behind the screens? First of all.. the composer.json file has changed. Look at the code that has been added.

 

Drupal8_002035.png

In the folder structure you see that sometimes the Vendor folder has been changed. Swiftmailer has a Vendor folder, Address not.

Drupal8_002036.png


Drupal8_002037.png

At last. Installing Colorbox or Views Slideshow witth composer does not add the third party libraries. I looked at the tutorials and i found out that it was quicker tot do it with FTP... on this moment. You need to manually add code to the composer.json.

Conclusion.. Composer will be a powerfull tool that will contribute to the success of drupal 8. You will be able to install modules without questioning which dependencies are needed. On this moment Drupal 8 is ruled by the programmers... They have many gifts... Explaining something simple is not one of them.