Skip to content

Instantly share code, notes, and snippets.

@opi
opi / ParagraphsBetterSummaryFormatter.php
Created Jan 29, 2021
mymodule/src/Plugin/Field/FieldFormatter/ParagraphsBetterSummaryFormatter.php A Better Paragraphs Summary Formatter
View ParagraphsBetterSummaryFormatter.php
<?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;
@opi
opi / OpiToolsCommands.php
Last active Jan 14, 2021
Drupal9 - Create field_group from drush command
View OpiToolsCommands.php
<?php
namespace Drupal\opitools\Commands;
use Drush\Commands\DrushCommands;
use Drupal\Core\Language\LanguageInterface;
/**
* A Drush commandfile.
*
@opi
opi / drupal7_contrib_update.sh
Created Dec 4, 2020
Automate Drupal7 contrib update
View drupal7_contrib_update.sh
#!/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"
}
@opi
opi / drupal7_core_update.sh
Created Dec 4, 2020
Automate Drupal7 core update
View drupal7_core_update.sh
#!/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"
}
@opi
opi / drupal_contrib_update.sh
Created Sep 14, 2020
Drupal 7 Contrib update
View drupal_contrib_update.sh
#!/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"
}
@opi
opi / drupal_contrib_update.sh
Created Mar 9, 2020
Drupal 7 contrib update
View drupal_contrib_update.sh
#!/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"
}
View drupal_deploy_prod.sh
#!/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"
}
# Get document root path
@opi
opi / module.php
Created Mar 11, 2019
Drupal 8 Custom form mode
View module.php
<?php
/**
* Implements hook_entity_form_display_alter().
*/
function MY_MODULE_entity_form_display_alter(&$form_display, array $context) {
if ($context['entity_type'] == 'node' && $context['bundle'] == 'MY_BUNDLE') {
$current_user = \Drupal::currentUser();
if ($current_user->hasPermission('CUSTOM PERMISSION')) {
$storage = \Drupal::entityManager()->getStorage('entity_form_display');
@opi
opi / a11y_question.md
Last active Sep 12, 2018
a11y_question.md
View a11y_question.md

a11y question

On a screen we want to display this sentence: Limit to X messages per Y, where X and Y are dropdown list of options.

On a screen reader we want 2 distinct fields with corresponding label:

  • Email send limit X
  • Email send time window Y

Note: Label are hidden with the .element-invisible class, using the clip method.

View backdrop_radios.php
<?php
$form['numeric_default_zero'] = array(
'#type' => 'radios',
'#title' => "Only numeric keys, starting at 0. #default_value to 0",
'#default_value' => 0,
'#options' => array(
0 => "key: 0",
1 => "key: 1",
2 => "key: 2",