Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Code

By editor , 26 November, 2020

Private Tempstore - Store data on Drupal 9 session

Tags

  • Drupal 8
  • Code
  • Drupal 9
  • Cache

This method allow to store data on drupal session using drupal session table (not php $_SESSION).
Storage is different for each users ans each visitors if anonymous

By editor , 8 November, 2020

Disable cache for specific page

Tags

  • Drupal 8
  • Code
  • Drupal 9

Syntax:

\Drupal::service('page_cache_kill_switch')->trigger();

 

Example on a controller:

By editor , 17 July, 2020

Download and Install drupal 9

Tags

  • Drupal 9
  • Code

Create a Drupal 9 project with composer

By editor , 9 July, 2020

Testing (SimpleTest) Install/Run Error

Tags

  • Drupal 8
  • Code
  • Testing

Error N°1 : PHPunit not found

If uou have a message like : Add Phpunit via composer

CAUTION : PHPunit Version >= 8 is not compatable with drupal, so use the 7

composer require --dev phpunit/phpunit:7

By editor , 11 October, 2019

Run PHP script using drupal bootstarp on drupal site

Tags

  • Drupal 8
  • Code
  • PHP

This is usefull if you want to do some actions just one time.

The drush comman is php-script alias src

On drupal 8 with drush

Example :
drush --uri=drupal.loc scr /modules/custom/mymodule/scripts/test-script.php

By nuwantha , 20 September, 2019

PHP RegEx Replace accents of each selected word

Tags

  • PHP
  • Code

Example :

$stopwords = ['toto', 'Pied', 'the'];
$str = 'bla bla toto bla bla Toto bla bla Tôtô bla bla totô bla bla bla bla the thé pied pïed pîéd';

By editor , 1 November, 2018

Alter Views title programmatically on Drupal 8

Tags

  • Drupal 8
  • Code
  • Views
  • Hook

function MYMODULE_views_pre_render(ViewExecutable $view) {
 if ($view->id() == 'ABC') {
  $view->setTitle('MY CUSTOM TITLE');
 }
}

By editor , 21 June, 2018

Create Drush 9 Commands For Drupal 8

Tags

  • Drupal 8
  • Code
  • Drush

Drush 9 is finally here with some much-awaited changes. Drush 9 commands are now classes and .inc files are obsolete. Drush commands will now be based on the Annotated Command format. This will change the fundamental structure of custom Drush commands.

By editor , 23 May, 2018

Search Entities when using Domain Access

Tags

  • Drupal 8
  • Code
  • Entity

Example 1 : Without changing user session.

$query = \Drupal::entityQuery('node');
$query->condition(DOMAIN_ACCESS_FIELD, 'domain_id'); // Set the domain id hear
$query->condition('type', 'article');
$query->condition('status', 1);

By editor , 23 May, 2018

Switch user sessions using Account Switcher service

Tags

  • Drupal 8
  • Code
  • Services

Example:

Pagination

  • Previous page
  • 2
  • Next page
Code

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer