Skip to content

Instantly share code, notes, and snippets.

@fazni
fazni / New PHP 8 features.md
Last active December 31, 2021 15:31
Cheat sheet - New PHP 8 features

1. Named arguments

<?php
// Positional arguments.
$pieces = explode('-', 'piece1-piece2-piece3');
 
// Named arguments.
$pieces = explode(delimiter: '-', string: 'piece1-piece2-piece3');
// or
@fazni
fazni / replacing-master-by-main-git.md
Last active June 16, 2020 09:39
Replacing "master" branch by "main" in git
fazni@drupal:~$ git checkout master
fazni@drupal:~$ git branch -m master main
fazni@drupal:~$ git fetch
fazni@drupal:~$ git branch --unset-upstream
fazni@drupal:~$ git branch -u origin/main
fazni@drupal:~$ git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
@fazni
fazni / Drush-create-csv-listing.md
Created June 13, 2020 17:54
Drush create a CSV file listing all your enabled modules
fazni@drupal:~$ drush pm-list --type=module --status=enabled --format=csv > module_list.csv
@fazni
fazni / Define-non-Drupal-dependencies.md
Last active June 8, 2020 21:01
Custom packages composer

Composer path repository

  • web/modules/custom/my-module/composer.json
  • composer.json
"repositories": [
  {
    "type": "composer",
 "url": "https://packages.drupal.org/8"
@fazni
fazni / settings.local-mode-dev-D8-D9.php
Last active June 2, 2020 16:30
D8/D9 - settings.local.php
// Logging.
$config['system.logging']['error_level'] = 'verbose';
$config['dblog.settings']['row_limit'] = 1000;
// Temp files.
$config['system.file']['path']['temporary'] = '/tmp';
// Aggregation.
$config['system.performance']['css']['preprocess'] = FALSE;
@fazni
fazni / EntityQuery Conditions.md
Created April 7, 2020 16:55
EntityQuery Conditions : orConditionGroup()
$query = \Drupal::entityQuery('node');

$group = $query->orConditionGroup()
  ->condition('uid', 22)
  ->condition('uid', 14)
  ->condition('uid.entity.name', 'admin')

$entity_ids = $query->condition('type', 'article')
 -&gt;condition($group)
@fazni
fazni / No available releases found.markdown
Last active March 31, 2020 10:07
Cannot update: “No available releases found”

Solution 1: SQL Query

DELETE FROM key_value WHERE collection = 'update_fetch_task';

Solution 2: hook_update_N()

$database = \Drupal::database();
$database
 -&gt;delete('key_value')
@fazni
fazni / Cheat sheet Drupal 8.md
Last active March 31, 2020 10:10
Cheat sheet Drupal 8

Run a single specific Drupal update hook using Drush

drush php-eval "module_load_install('MYMODULE'); MYMODULE_update_NUMBER();"
@fazni
fazni / gist:3af40ba86de29d3562212c5733566818
Created January 30, 2020 09:33
Updates the installed version information for a module.
drush ev "drupal_set_installed_schema_version('module_name', 8801)"
@fazni
fazni / gist:f5759fb6b3098026a7d404bc0e5af574
Created October 24, 2019 12:14 — forked from luisbosque/gist:5513fa88b5087434089d
Export to csv format the list of remote branches and their "owners"
for i in `git branch -a |grep remotes |awk '{print $1}' | cut -d"/" -f 3,4,5 |grep -v ^master$ |grep -v ^HEAD$`; do echo "`git log -1 --pretty=format:\"%an (%ae)\" origin/$i`|$i"; done |sort > /tmp/branches.csv