Blog

  • [Drupal] Perfect views block configuration for multilingual node support

    Objectives We want to add on a node page layout a block which uses a field from the currently rendered content (node). We want this block to be translated the same as the currently rendered entity. As a anonymous user, we want it to respect the published settings of the currently rendered entity. As an…

  • [Drupal] Custom scrollbars with Overlay Scrollbars library

    The road to custom scrollbars Reminiscing. I am currently working on a website for a video game reviews project I have had with an old friend of mine (FuuDoh). Obviously, I have switched to Drupal to get a result quicker than what I would get with the PHP only solution I have been working on…

  • [Drupal] Change CKEditor behaviour for line breaks (br or p)

    Here is a little code snippet to be added in a .module file. /** * Implements hook_editor_js_settings_alter(). * * {@inheritdoc} */ function MODULE_editor_js_settings_alter(array &$settings) { foreach ($settings[‘editor’][‘formats’] as $name => $value) { // Use instead of on enter. // See: https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR.html#property-ENTER_BR. // CKEditor natively converts double into on rendering. $settings[‘editor’][‘formats’][$name][‘editorSettings’][‘enterMode’] = ‘2’; } } Additional…

  • [Drupal] Make the Search API Page search block appear in Bootstrap markup

    When using Search API Page, I needed to theme the search form in the bootstrap structure. The cleanest answer I have found is to add some variables to trigger the bootstrap overrides on the search form. /** * Implements hook_form_FORM_ID_alter(). */ function MYMODULE_form_search_api_page_block_form_alter(&$form, FormStateInterface $form_state, $form_id) { // We need this to make our search_api_page_block_form…

  • [Drupal] VM + XDebug + Netbeans

    Hey! Long time no see! Heehee. I am just dropping a note here about the basic steps of how to install XDebug for a specific setup. Here is my configuration: host: OS: Windows 7 64 bits IP: 192.168.0.3 IDE: Netbeans 8.2 guest: OS: Debian Jessie 64 bits in VirtualBox IP: 192.168.0.4 (bridged network in VirtualBox…

  • [Drupal] Use admin_block and admin_block_content templates

    This article is about the default admin_page, admin_block and admin_block_content templates which serves as the base of the content display on some system configuration pages such as the one on this image: The code

  • Replace image URLs in WordPress posts from http to https

    I just switched my website to https for testing purpose. But changing the website’s URL to https:// is not sufficient to enable a fully secure browsing experience, as images in posts are still loaded from http://. Or more precisely, most modern browsers (FF or Opera for instance) are now clever enough to guess that the…

  • [Drupal] Base hook schema example to put in .install

    Introduction Delighted hook_schema is one of those methods where you are happy to have a usable documentation on the api website. It is pretty much self-explanatory and you don’t have to look for hours on third parties websites to get some usable information. 🙂 hook_schema on api.drupal.org and don’t forget to select your Drupal version!…

  • [Drupal] Table render array example structure

    Result The code public function controllerCallbackExample() { return [ ‘#type’ => ‘table’, ‘#caption’ => ‘This is a caption. Use a translated string here.’, ‘#header’ => [ ‘Header 1’, ‘Header 2’, ‘Header 3’, ‘Header 4’ ], ‘#rows’ => [ [ ‘Row 1 Cell 1’, ‘Row 1 Cell 2’, ‘Row 1 Cell 3’, [‘data’ => ‘Row 1…

  • [Drupal] Create an event subscriber

    Instructions I will be creating a dedicated module using Drupal Console for this event subscriber. But feel free to use your own if you already have one! (don’t forget to backup) Access the drupal root folder in command line. Generate a new module: dakwamine@debian-drupal:/var/www/html/drupal$ drupal generate:module Enter the new module name: > Test Module Enter…

  • [Drupal] Service dependency injection in a service type class

    The code services: my_module.event_subscriber: # Your service class class: Drupal\my_module\Entity\EventSubscriber\MyModuleSubscriber # Add your services to load here in the array arguments: [‘@current_user’] tags: # For this example, I am making an event subscriber class – { name: event_subscriber }