Skip to content

Instantly share code, notes, and snippets.

View MatthieuScarset's full-sized avatar
🤷‍♂️
Probably me

MattGyver MatthieuScarset

🤷‍♂️
Probably me
View GitHub Profile
@MatthieuScarset
MatthieuScarset / mymodule.install
Created April 16, 2024 15:41
Drupal - Hook update to copy values from one field to another - runs after config import
<?php
// drush updb ; trigger expection so the update don't pass.
// drush cim ; import your new field.
// drush updb ; the hook update is successfull and values are copied.
/**
* Populate formatted texts from previous field on paragraph callout.
*/
function mymodule_update_10103(&$sandbox): void {
@MatthieuScarset
MatthieuScarset / keybindings.json
Last active March 6, 2024 09:28
VSCode keybinding
[
{
// Open/close integrated terminal.
"key": "ctrl+shift+'",
"command": "workbench.action.terminal.toggleTerminal"
},
{
"key": "ctrl+shift+down",
"command": "editor.action.moveLinesDownAction",
"when": "editorTextFocus"
@MatthieuScarset
MatthieuScarset / .lando.yml
Last active January 4, 2024 15:03
Correct settings for XDebug + VSCode + Lando (+3.0)
# Lando version is at least +3.0
name: drupal-nine
recipe: drupal9
services:
appserver:
webroot: web
xdebug: debug
config:
php: .vscode/php.ini
@MatthieuScarset
MatthieuScarset / MyCustomForm.php
Last active November 11, 2023 20:24
Drupal - Autosubmit exposed form in JS
<?php
namespace Drupal\mymodule\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a custom form.
*/
@MatthieuScarset
MatthieuScarset / .lando.yml
Created December 13, 2020 20:23
Lando (+3.0) with XDebug (WordPress recipe)
name: wordpress
recipe: wordpress
services:
appserver:
webroot: .
xdebug: debug
config:
php: .vscode/php.ini
tooling:
install:wordpress:
@MatthieuScarset
MatthieuScarset / field_group_delete.php
Created September 19, 2023 13:20
Drupal - Programmatically delete field_group from form and view displays
<?php
$entity_type = 'node';
$group_name = 'the_group_id';
$context = 'form';
$form_displays = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->loadByProperties(['targetEntityType' => 'node']);
foreach ($form_displays as $display) {
@MatthieuScarset
MatthieuScarset / settings.json
Last active September 18, 2023 04:05
VSCode settings
{
// Tracking shit.
"telemetry.telemetryLevel": "off",
"enableTelemetry": false,
"hardhat.telemetry": false,
"redhat.telemetry.enabled": false,
"gitlens.advanced.telemetry.enabled": false,
// Global
"debug.toolBarLocation": "docked",
"debug.allowBreakpointsEverywhere": true,
@MatthieuScarset
MatthieuScarset / composer.json
Created August 29, 2023 11:56
PHPCS - One line format file (composer custom script)
// Format/fix uncommitted files
"scripts": {
"codefix": "for F in $(git diff --name-only); do vendor/bin/phpcbf \"$F\"; done",
}
// ...
@MatthieuScarset
MatthieuScarset / fullclick.scss
Last active July 17, 2023 14:56
Make HTML element fully clickable (e.g. card <div> with a link)
/// Make element fully-clickable.
/// @author Matthieu Scarset
/// @param string $element
/// (optional) The button element which should get the click. Default: 'a'.
/// @param string $wrapper
/// (optional) The element's HTML wrapper(s), useful if convoluted markup. Default: empty string.
/// @link https://gist.github.com/MatthieuScarset/397da3b000ce6d9523dd50f525eabaf0
///
/// @example Simple card div with the link directly inside.
/// <div class="fullclick">
@MatthieuScarset
MatthieuScarset / drupal8_programatically_delete_content.php
Last active July 6, 2023 23:23
Programatically delete content in Drupal 8
// Enable Devel module and go to /devel/php
$nodes = \Drupal::entityQuery("node")
->condition('created', strtotime('-30 days'), '<=')
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
// $entities = $storage_handler->loadMultiple(); // Delete ALL nodes.
$entities = $storage_handler->loadMultiple($nodes);
$storage_handler->delete($entities);