Skip to content

Instantly share code, notes, and snippets.

View fredysan's full-sized avatar

Fredy Sánchez Téllez fredysan

View GitHub Profile
@fredysan
fredysan / Sort Menu Items - Drupal 8
Last active January 20, 2020 22:18
Sort menu Items - Drupal 8
<?php
namespace Drupal\wb_theme\Plugin\Preprocess;
use Drupal\Core\Menu\MenuLinkTreeInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
@fredysan
fredysan / remove-setting.php
Last active January 22, 2020 18:40
Remove Drupal Settings Programmatically
<?php
/**
* @file
* Remove Drupal 8 Settings.
*/
\Drupal::configFactory()->getEditable('automated_cron.settings')->delete();
// Or.
\Drupal::service('config.factory')->getEditable('automated_cron.settings')->delete();
@fredysan
fredysan / CrawlerRemoveImages.php
Last active February 4, 2020 23:33
Remove image tags conditionally based on src content
<?php
use Symfony\Component\DomCrawler\Crawler;
class CustomCrawler {
protected function removeExtLinkImages($value) {
$value = '<body>' . $value . '</body>' ?: '';
$crawler = new Crawler($value, 'http://localhost');
// Remove all Icon_External_Link.png images.
@fredysan
fredysan / migrate_plus.migration.paragraph.yml
Last active May 13, 2020 17:06
Config file describing how to reference paragraphs during a migration
uuid: a2c81f98-bbd0-4cac-af95-c556b76731e1
langcode: en
status: true
dependencies:
enforced:
module:
- mymodule
id: node_with_paragraph
class: null
field_plugin_method: null
@fredysan
fredysan / LayoutBuilderComponents.php
Last active May 28, 2020 16:04
Navigate through Layout Builder Components
<?php
namespace Drupal\module\Service;
use Drupal\node\NodeInterface;
/**
* Helper Class.
*/
class Helper {
@fredysan
fredysan / DOCKER_CHEAT_SHEET.md
Last active August 6, 2020 15:01
Docker Cheat Sheet

Docker Cheat Sheet

List images

$ docker images

List running containers

@fredysan
fredysan / Drupal and Solr with Docksal.md
Last active June 24, 2021 16:06
Could Not Create Docksal recipe to install Drupal 8 and Solr 6/7/8 with Docksal

Drupal 8 and Solr 6/7/8 with Docksal installation and configuration.

  • Drupal site path in the host
~/Sites/d8-solr
  • Docksal settings
@fredysan
fredysan / SymfonyConsoleDocksal.md
Last active August 10, 2020 02:01
Run Symfony Console Commands with Docksal

Run Symfony Console Commands with Docksal

Create a new composer package

Add a new folder with the following structure to your .docksal folder

$ cd .docksal

$ tree
@fredysan
fredysan / PdfGeneratorController.php
Last active August 28, 2020 14:36
How to generate Styled PDF files
<?php
namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;
use Dompdf\Dompdf;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
@fredysan
fredysan / LicenseModalBlock.php
Last active September 29, 2020 19:55
License Agreement Modal Block
<?php
namespace Drupal\license_modal\Plugin\Block;
use Drupal\license_modal\Form\AcceptLicenseForm;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;