Skip to content

Instantly share code, notes, and snippets.

@opi
opi / getWithFallback.php
Last active February 21, 2024 09:47
iea_migrate_partners.yml
<?php
namespace Drupal\iea_migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateException;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
@opi
opi / BlogAuthorComputed.php
Created October 21, 2021 12:22
Computed field example for Drupal 8/9
<?php
// in MY_MODULE/src/ComputedField/BlogAuthorComputed.php
namespace Drupal\MY_MODULE\ComputedField;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
class BlogAuthorComputed extends EntityReferenceFieldItemList {
@opi
opi / my_module.php
Last active November 11, 2021 14:46
Extra field example for drupal 8/9
<?php
/**
* Implements hook_entity_extra_field_info().
*/
function MYMODULE_entity_extra_field_info() {
$extra = [];
foreach (NodeType::loadMultiple() as $bundle) {
@opi
opi / ViewsPagerAsBlock.php
Created September 28, 2021 11:41
Drupal Views pager as block
<?php
namespace Drupal\mymodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\views\Views;
/**
@opi
opi / d8_contrib_update.sh
Created July 21, 2021 12:08
D8/D9 : Auto update contrib with composer and Git commit
#!/bin/bash
function greenecho {
echo "" && echo -e "\e[30;48;5;82m ✔ $1 \e[0m"
}
function orangeecho {
echo "" && echo -e "\e[30;48;5;208m ⚠ $1 \e[0m"
}
greenecho "Here we are: "$(pwd)
@opi
opi / README.md
Created June 11, 2021 08:55
Drupal 9 : Migrate D7 body field to paragraph
  1. Run body_to_paragraph migration
  2. Run my_node_migration migration
@opi
opi / drupal_sticky_nav_with_debounce.md
Last active May 6, 2021 09:04
Drupal : Sticky navigation with debounce

In yourtheme.libraries.yml

global:
  js:
    dist/js/global.js: { minified: true }
  dependencies:
    - core/drupal
    - core/drupal.debounce
@opi
opi / drupal_dialog_buttonpane.md
Created April 26, 2021 11:14
Drupal: Do not put buttons into modal/dialog button pane
@opi
opi / ParagraphsBetterSummaryFormatter.php
Created January 29, 2021 08:09
mymodule/src/Plugin/Field/FieldFormatter/ParagraphsBetterSummaryFormatter.php A Better Paragraphs Summary Formatter
<?php
namespace Drupal\mobilis\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;