Drupal Blog http://karimboudjema.com/en en The 'node_list' cache tag pitfall in Drupal 8 views http://karimboudjema.com/en/drupal/20190909/node-list-cache-tag-pitfall-drupal-8-views The node_list cache tag is generated automatically when we create a view that displays nodes entity type in Drupal 8. This cache tag will invalidate the cache of all views that list any kind of nodes (page, article, ....) when we make a CUD (create, update, delete) action on any kind of nodes.<br /> <br /> This is a very good cache invalidation strategy since when we modify a node through a CUD action, the cache of every views that display nodes will be invalidate to reflect this new change. Yes, the improvements in the new Drupal8 Cache API are amazing! Thanks to all the contributors (like Wim Leers) to make this possible. Mon, 09 Sep 2019 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/33 VideoDrupal.org: A new site of Drupal videos tutorials http://karimboudjema.com/en/drupal/20190424/videodrupalorg-new-site-drupal-videos-tutorials <br /> After three months of hard work, mostly at night and during the weekends, we finally launched the first minimal viable version of VideoDrupal.org (beta 1.0), a curated mashup of Drupal video tutorials published on Youtube to make them more accessible for personal, educational and professional purposes.<br /> <br /> For 2019, I've set up three main goals: improve my English, find a "real" Drupal Team to work with and launch this website. So, I've reached one of my goals. Checked! To be honest, I think it was the easiest one. Improving my English and finding a community-oriented Drupal agency will be harder. But I'm working on it! Wed, 24 Apr 2019 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/32 Saving temporarily values of a form with Private Tempstore in Drupal 8 http://karimboudjema.com/en/drupal/20190315/saving-temporary-values-form-private-tempstore-drupal-8 In this post we’ll see how to save temporarily values from a form and how to retrieve or process them later in a controller. To do that, we’ll use the Form API and the private tempstore (the temporary store storage system of Drupal 8).<br /> <br /> The use case is the following: we need to build a simple RSS reader (a form) where the user could introduce the URL of an RSS file and the number of items to retrieve from that file.  Next, in a new page (a controller), the application should display the list of items with a link to each syndicated page .<br /> <br /> The easiest way to achieve it would be to retrieve the values in our buildForm() method, process them and display the result thought a specific field of the form. But that’s not our use case. Fri, 15 Mar 2019 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/31 10 helpful Drupal 8 modules for 2019 http://karimboudjema.com/en/drupal/20190109/10-helpful-drupal-8-modules-2019 It’s not easy to create a list of the most useful Drupal 8 modules because it really depends on the site you will create or manage. But there are some really helpful modules that you can use in almost all cases.<br /> <br /> In this post, I will share a list of modules that I use on almost all my Drupal 8 projects. They aren’t specifically for a particular type of site, but I find that they are always helpful, both in development and production environments.<br /> <br /> 1. Admin Toolbar<br /> <br /> (D8) - https://www.drupal.org/project/admin_toolbar<br /> The Admin Toolbar module will save you a great deal of time. It provides a drop-down menu that extends Drupal built in menu. It allows you to perform various admin actions faster and easier.<br /> <br /> The module works on the top of the default toolbar core module. It’s a very light module and keeps all the toolbar functionalities (shortcut / media responsive). Wed, 09 Jan 2019 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/30 How to Run Batch Processing with a Custom Drush 9 Command in Drupal 8 http://karimboudjema.com/en/drupal/20181127/how-run-batch-processing-custom-drush-9-command-drupal-8 Batch processing is usually an important aspect of any Drupal project and even more when we need to process huge amounts of data.<br /> <br /> The main advantage of using batch is that it allows large amounts of data to be processed into small chunks or page requests that run without any manual intervention. Rather than use a single page load to process lots of data, the batch API allows the data to be processed as number of small page requests.<br /> <br /> Using batch processing, we divide a large process into small pieces, each one of them executed as a separate page request, thereby avoiding stress on the server. This means that we can easily process 10,000 items without using up all of the server resources in a single page load.<br /> <br /> This helps to ensure that the processing is not interrupted due to PHP timeouts, while users are still able to receive feedback on the progress of the ongoing operations.<br /> <br /> Some uses of the batch API in Drupal: Tue, 27 Nov 2018 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/25 Create a custom form with Form API in Drupal 8 http://karimboudjema.com/en/drupal/20181013/create-custom-form-form-api-drupal-8 Creating forms is part of the day to day live of a Drupal programmer.  Forms are represented as nested arrays in both Drupal 7 and Drupal 8. But they are different in that in Drupal 7 you define your form arrays in functions and in Drupal 8 you create a form class.<br /> <br /> In this post we’ll create a custom form with two fields, a text field and a checkbox field, we’ll validate those fields, display them in a message and finally redirect the user to the home page.<br /> <br /> You can find the code of this module here.<br /> <br /> Here is a screenshot of the form:<br /> You can see the folder structure of this module below: Sat, 13 Oct 2018 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/9 Create a config form in Drupal 8 http://karimboudjema.com/en/drupal/20180924/create-config-form-drupal-8 In Drupal 7, to manage system variables, we used variable_get() / variable_set() /  variable_del() calls and stored those variables in the variable table of the database.<br /> <br /> In Drupal 8 we now use the Configuration system which provides a central place for modules to store configuration data. This system allows to store information that can be synchronized between development and production sites. This information is often created during site building and is not typically generated by regular users during normal site operation.<br /> In Drupal 8 configuration is still stored in the database,  but it can now be synced with YML files on the disk for deployment purposes aswell.<br /> <br /> In this post we will create a configuration form that stores a configuration value in our system. In this case it will be a form that stores the value of an external API key. Next, we will retrieve this value and use it in a very simple controller.<br /> <br /> 1. Create the module<br /> 2. Create the form<br /> 3. Check the form<br /> 4. Retrieve the config information in a controller<br /> <br /> 1. Create the module skeleton<br /> <br /> We use the following Drupal Console command. Mon, 24 Sep 2018 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/8 Create a queue with a Controller in Drupal8 http://karimboudjema.com/en/drupal/20180807/create-queue-controller-drupal8 Queues are particularly important when we need to stash some tasks for later processing. To do so, we are going to put some tasks or data in a queue (create the queue) and later we will process those tasks with a QueueWorker plugin (process the queue), usually triggered by cron.<br /> <br /> There are several ways to create a queue:<br /> - With a form class<br /> - With a controller class<br /> - With a hook_cron() function<br /> &nbsp;<br /> To process the queue, we also have different options:<br /> - As a cron process with a QueueWorker plugin<br /> - As a batch process also with QueueWorker plugin but extending a base plugin<br /> - As a batch process claiming each item of the queue in a service or in a controller<br /> <br /> Today we'll create the queue with a controller and process it with a QueueWorker plugin when cron runs or manually with Drupal Console. Tue, 07 Aug 2018 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/10 Speed up composer with Drupal 8 http://karimboudjema.com/en/drupal/20180604/speed-composer-drupal-8 Runing composer install or composer update on your Drupal 8 installation to install or update modules and themes could be sometimes frustrating because it can be very slow. Too slow in fact. But it doesn't have to be that way. Here are some tips to speed your Composer working with Drupal.<br /> <br /> Install Prestissimo<br /> <br /> Prestismo is a global composer plugin that that enables parallel installations and it's very fast! It can be more than 2x faster. But Prestissimo requires cURL, which may not work behind certain firewalls or proxies.<br /> <br /> To install prestissimo follow these steps:<br /> <br /> <br /> composer self-update<br /> <br /> composer global require hirak/prestissimo<br /> <br /> <br /> <br /> Once it is installed, Composer should install a new project much faster than before.<br /> <br /> You can configure how many connections you would prefer, but I have found that the default of 6 seems to be pretty good.<br /> <br /> To uninstall: Mon, 04 Jun 2018 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/7 Install (download) Drupal 8 with composer http://karimboudjema.com/en/drupal/20180603/install-download-drupal-8-composer Today composer is the recommended approach to install (o more precisely to download)&nbsp; Drupal 8. This is true for the core but also for contributed modules and themes.<br /> <br /> So now, to start a new Drupal 8 project, we need to download it via composer and not as we did before with drush or drupal console. Of course, we'll still use drush or drupal console to install contrib modules or themes, but not for downloading them.<br /> <br /> The main benefit of using composer is that it allows us to systematically manage a sprawling list of dependencies (and their subsidiary dependencies) and ensure that the right versions for each package are used or updated.<br /> <br /> An official project composer template has been created for installing Drupal with composer. We will create our project directly using this template, which is also available on Packagist. Sun, 03 Jun 2018 12:00:00 +0000 Karim Boudjema http://karimboudjema.com/6