Skip to content

Instantly share code, notes, and snippets.

View DuaelFr's full-sized avatar

Edouard Cunibil DuaelFr

View GitHub Profile
@DuaelFr
DuaelFr / grumphp.yml
Created October 19, 2023 11:08
GrumPHP git blacklist example for Drupal
grumphp:
tasks:
git_blacklist_twig:
metadata:
task: git_blacklist
keywords:
- "dump("
- "kint("
- "|raw"
- "autoescape"
<?php
namespace Drupal\my_module\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter as ResponsiveImageFormatterCore;
/**
* Responsive image formatter that allow to force the format.
@DuaelFr
DuaelFr / Spreadsheet.php
Last active January 3, 2020 10:29
Override migrate_spreadsheet to have basic XLSX formatting support
<?php
// src/Plugin/migrate/source/Spreadsheet.php
namespace Drupal\my_project\Plugin\migrate\source;
use Drupal\my_project\SpreadsheetIterator;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_spreadsheet\Plugin\migrate\source\Spreadsheet as SpreadsheetContrib;
use PhpOffice\PhpSpreadsheet\IOFactory;
@DuaelFr
DuaelFr / scripts---solr---init_cores.sh
Last active May 14, 2019 13:09
Script that takes cores from Drupal config and tries to create them via Solr REST API
#!/usr/bin/env bash
# Return error codes if they happen.
set -e
# Working directory.
# Helper to let you run the install script from anywhere.
currentscriptpath () {
SOURCE="${BASH_SOURCE[0]}"
# resolve $SOURCE until the file is no longer a symlink
@DuaelFr
DuaelFr / ReferenceLastDate.php
Created February 7, 2019 14:03
Drupal 8 Search API processor example
<?php
namespace Drupal\hc_core\Plugin\search_api\processor;
use Drupal\node\Entity\Node;
use Drupal\search_api\Datasource\DatasourceInterface;
use Drupal\search_api\IndexInterface;
use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\search_api\Processor\ProcessorProperty;
@DuaelFr
DuaelFr / defcontent.sh
Last active July 25, 2018 14:36
Outputs the list of entity types and uuids contained by a content directory of a default_content module
#!/bin/bash
# How to use this script?
#
# 1. create an empty module that depends on default_content or reuse an
# existing one.
# 2. use `drush dcer --folder=path/to/module/content ENTITY_TYPE ID`
# to add default content to your module.
# 3. once all your content is in your module, clean up the content folder
# to only keep the content you need (ie. remove users most of the time).
@DuaelFr
DuaelFr / clickable-node.js
Created February 12, 2018 10:55
Make a node fully clickable while respecting clicks on links/buttons/contextuals
(function ($, Drupal) {
'use strict';
/**
* Handle click on a node so it redirects to the location of its first link.
*/
Drupal.behaviors.clickableNode = {
attach: function (context, settings) {
$('.js-clickable-node').once('clickableNode')
.on('mouseup.clickableNode', function (evt) {
@DuaelFr
DuaelFr / MY_MODULE.module
Last active January 15, 2018 15:19
Webform in a Paragraph (D8)
<?php
use Drupal\webform\Entity\Webform;
/**
* Implements hook_entity_extra_field_info().
*/
function MY_MODULE_entity_extra_field_info() {
$extra['paragraph']['PARAGRAPH_TYPE']['display']['FIELD_NAME'] = [
'label' => t('Form'),
@DuaelFr
DuaelFr / drush7.sh
Created October 9, 2017 10:03
Drush launcher lite for Drupal 7 and Drush 8 installed locally
#!/bin/bash
BASEDIR=vendor/bin/drush
if [ ! -f $BASEDIR ]; then
BASEDIR=../$BASEDIR
fi
$BASEDIR $@
@DuaelFr
DuaelFr / my_module.install
Created October 4, 2017 08:08
Hook update to change all content to French in Drupal 8
/**
* Enable language module, delete english and set french as default.
*/
function my_module_update_N() {
\Drupal::service('module_installer')->install(['language']);
// Enable french language and set it as default.
if (NULL === ConfigurableLanguage::load('fr')) {
ConfigurableLanguage::create([
'id' => 'fr',