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 / 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 / MyCustomForm.php
Last active August 28, 2024 05:48
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 / drupal_get_title_from_url_module.php
Last active November 25, 2022 14:24
Get the page title from a Url in Drupal 8+
<?php
/**
* @file
* Contains a custom function to get the title from a Url.
*/
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
@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">
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
// Unlike the string type, ShortString is a value type that can be made immutable.
// It supports strings of at most 32 bytes and assumes they don't contain null bytes.
type ShortString is bytes32;
error StringTooLong(string s);
@MatthieuScarset
MatthieuScarset / basefields.php
Last active August 28, 2024 05:51
Drupal 8 - Programatically create new fields
<?php
/**
* Implements hook_entity_base_field_info().
*/
function mymodule_entity_base_field_info(EntityTypeInterface $entity_type) {
if ($entity_type->id() == 'user') {
$fields = [];
$default_field_definition = [
@MatthieuScarset
MatthieuScarset / entity_autocomplete_views.php
Created July 19, 2021 11:13
Drupal selection handlers views
$args = [];
$form['user_in_charge'] += [
'#title' => t('Entity autocomplete'),
'#type' => 'entity_autocomplete',
'#selection_handler' => 'views',
'#selection_settings' => [
'view' => [
'view_name' => 'view_machine_name',
'display_name' => 'entity_reference',
@opi
opi / drupal_dialog_buttonpane.md
Created April 26, 2021 11:14
Drupal: Do not put buttons into modal/dialog button pane
@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 / reorder-form-actions.php
Created July 14, 2020 14:17
Drupal - Order array by another array
<?php
// Reorder actions.
$order = [
'previous',
'reset',
'submit',
'preview_next',
];