Skip to content

Instantly share code, notes, and snippets.

View DuaelFr's full-sized avatar

Edouard Cunibil DuaelFr

View GitHub Profile
@DuaelFr
DuaelFr / embed_video.html.twig
Created February 4, 2025 10:50
Embed video with replacement on click
<div class="embed-video">
<div class="embed-video__thumbnail">
{{ thumbnail }}
<button class="embed-video__button">
<span class="visually-hidden">{% trans %}Play{% endtrans %}</span>
<svg height="100%" version="1.1" viewBox="0 0 68 48" width="100%"><path class="ytp-large-play-button-bg" d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z" fill="#f00"></path><path d="M 45,24 27,14 27,34" fill="#fff"></path></svg>
</button>
</div>
<div class="embed-video__video">
<!--
@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 $@