Drupal Dump

Drupal Snippets, Hacks and more....

495 posts since 2011

JSON:API disable caching locally

To disable caching while testing your JSON:API endpoints you should put this into your settings.php

$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

but for this to work, you need to define this service null, which should be added as

Get list of all installed modules and their dependencies

You probably don't need this but for debugging purposes i checked system.install file and saw how dependencies are checked on drupal updates.
So to get full list of modules and its info run

$files = \Drupal::service('extension.list.module')->getList();

to get theme info go

How to find hook_update_N, current N value

To find it via drush, run this command 

drush php:eval "echo drupal_get_installed_schema_version('modul_name');"

also if you want to look it up with some DB admin tool, look under table `key_value`,  `system.schema` collection row, with a `name` of your module and you will get value of last run update.

Dumping and exporting DB with drush and piping to ZIP

If you want to import DB that is in ZIP format with one line

gunzip -c my_db.sql.gz | drush sqlc

to dump DB to ZIP file write this

drush sql-dump --gzip --result-file=my_db.sql

you will end up with my_db.sql.gz file.

Rsyslog using severities, templating and datadog integration

Basic setup

So I will assume you installed syslog and have some default config running for it with syslog_facility set to log_local0. With that lets assume you are using rsyslog and you have config for it in

/etc/rsyslog.conf

which could have all config in this file or separated config files that are included with

Adding JS with library without jquery or jquery-once dependency

If you want to add some JS code, like some kind of snippet to your pages with libraries.yml, add it as any other library item but don't use jquery or drupal behaviours in .js code, add some plain JS code like

document.addEventListener("DOMContentLoaded", function() {

so to wrap some JS snippet for it, do it like below.

Recursively renaming files and folders with PHP

I wanted to rename lots of filed and folders for my modules, but not to do it manually I made an php script that does this for me. Also I used my IDE to rename code(class names and methods). So just replace root where is the code you want to change file and folder names and do that for strings also.

Block build output, theme and allowed_tags tags

To output block, you can attach which theme template will output it, which library to attach to it, what markup will be outputed and in the end what tags can be in this markup