Skip to content

Instantly share code, notes, and snippets.

View Mykola-Veryha's full-sized avatar
🏠
Working from home

Mykola Veryha Mykola-Veryha

🏠
Working from home
View GitHub Profile
FROM surnet/alpine-wkhtmltopdf:3.9-0.12.5-full as wkhtmltopdf
FROM wodby/drupal-php:7.4-dev-4.15.3
USER root
# Install dependencies for wkhtmltopdf
RUN apk add --no-cache \
libstdc++ \
libx11 \
libxrender \
<?php
namespace Drupal\ln_follow_and_alert\Form;
use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@Mykola-Veryha
Mykola-Veryha / truncate_html.php
Last active April 11, 2020 18:15
Truncate html
<?php
function htmlTruncate(string $html, int $max_lenght) {
$dom= new \DOMDocument();
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$xpath = new \DOMXPath($dom);
$body = $xpath->query('/html/body')->item(0);
$prev_lenght = 0;
@Mykola-Veryha
Mykola-Veryha / StandardWithStyles.php
Last active January 26, 2020 15:40
EditorXssFilter with styles. Drupal 8.
<?php
namespace Drupal\MODULE_NAME\EditorXssFilter;
use Drupal\Component\Utility\Html;
use Drupal\editor\EditorXssFilter\Standard;
/**
* Defines the standard text editor with styles XSS filter.
*/
@Mykola-Veryha
Mykola-Veryha / editor_xss_filter_alter.php
Created January 26, 2020 14:28
editor_xss_filter_alter in Drupal 8
<?php
/**
* Implements hook_editor_xss_filter_alter().
*/
function MODULE_NAME_editor_xss_filter_alter(
&$editor_xss_filter_class,
FilterFormatInterface $format,
FilterFormatInterface $original_format = NULL
) {
@Mykola-Veryha
Mykola-Veryha / editor_filter_xss.php
Created January 26, 2020 14:06
editor_filter_xss in Drupal 8
<?php
/**
* Applies text editor XSS filtering.
*
* @param string $html
* The HTML string that will be passed to the text editor.
* @param \Drupal\filter\FilterFormatInterface|null $format
* The text format whose text editor will be used or NULL if the previously
* defined text format is now disabled.
@Mykola-Veryha
Mykola-Veryha / LinkTitleFilter.php
Created January 26, 2020 13:49
Create own custom CKEditor filter
<?php
namespace Drupal\MODULE_NAME\Plugin\Filter;
use Drupal\Component\Utility\Html;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
/**
* Filter Link Title attribute.
@Mykola-Veryha
Mykola-Veryha / remove_a_deleted_term_entity.php
Created November 27, 2019 00:00
How to remove a deleted term entity from Entity Reference field after deleting the term entity.
<?php
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
/**
* Implements hook_ENTITY_TYPE_delete() for taxonomy_term entities.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
@Mykola-Veryha
Mykola-Veryha / taxonomy_index.php
Created November 26, 2019 23:33
How taxonomy index work
<?php
/**
* Implements hook_ENTITY_TYPE_insert() for node entities.
*/
function taxonomy_node_insert(EntityInterface $node) {
// Add taxonomy index entries for the node.
taxonomy_build_node_index($node);
}
/**
* Implements hook_ENTITY_TYPE_update() for node entities.
@Mykola-Veryha
Mykola-Veryha / MODULE_NAME.libraries.yml
Last active March 1, 2021 15:11
Drupal 8 Add class to body after opening a modal window
add_class_to_body:
js:
js/add_class_to_body.js: {}