Skip to content

Instantly share code, notes, and snippets.

View flocondetoile's full-sized avatar

Flocon de toile flocondetoile

View GitHub Profile
@flocondetoile
flocondetoile / drupal_sticky_nav_with_debounce.md
Created May 6, 2021 09:04 — forked from opi/drupal_sticky_nav_with_debounce.md
Drupal : Sticky navigation with debounce

In yourtheme.libraries.yml

global:
  js:
    dist/js/global.js: { minified: true }
  dependencies:
    - core/drupal
    - core/drupal.debounce
@flocondetoile
flocondetoile / Blocks.md
Created February 27, 2021 11:37 — forked from bdlangton/Blocks.md
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@flocondetoile
flocondetoile / OpiToolsCommands.php
Created January 14, 2021 10:53 — forked from opi/OpiToolsCommands.php
Drupal9 - Create field_group from drush command
<?php
namespace Drupal\opitools\Commands;
use Drush\Commands\DrushCommands;
use Drupal\Core\Language\LanguageInterface;
/**
* A Drush commandfile.
*
#!/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
@flocondetoile
flocondetoile / import.php
Created November 29, 2019 23:33 — forked from crittermike/import.php
Importing Drupal 8 config programmatically
<?php
// Import arbitrary config from a variable.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
// Or, import YAML config an arbitrary directory.
@flocondetoile
flocondetoile / EditorImageStyle.php
Created June 26, 2019 23:10 — forked from mortenson/EditorImageStyle.php
A custom Drupal 8 filter plugin to use an image style for image embedss custom Drupal 8 filter plugin to use an image style for image embeds. A custom Drupal 8 filter plugin to use an image style for image embeds.
<?php
namespace Drupal\ppdx_editor\Plugin\Filter;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Image\ImageFactory;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\file\FileInterface;
use Drupal\filter\FilterProcessResult;
@flocondetoile
flocondetoile / module.php
Created March 11, 2019 13:20 — forked from opi/module.php
Drupal 8 Custom form mode
<?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');
@flocondetoile
flocondetoile / progress.html
Created February 24, 2019 11:24 — forked from hlorand/progress.html
jQuery reading position indicator progress bar
<!doctype html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
var getMax = function(){
@flocondetoile
flocondetoile / progressbar.css
Created February 24, 2019 11:23 — forked from kmelve/progressbar.css
jQuery snippet for making a progressbar for reading position in browser.
#progresswrapper {
position: fixed;
top: 0px;
height: 2px;
width: 100%;
z-index: 1000;
}
#progressbar {
top: 0;
position: fixed;
@flocondetoile
flocondetoile / ReferenceLastDate.php
Created February 7, 2019 14:30 — forked from DuaelFr/ReferenceLastDate.php
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;