Skip to content

Instantly share code, notes, and snippets.

View drubb's full-sized avatar

Boris Böhne drubb

View GitHub Profile
@drubb
drubb / EntityEditLinkTwigExtension.php
Last active February 6, 2024 08:46
Custom Twig extension to provide links to an entity edit form. Permissions are checked, the current page is added as destination, and the link is styled using a fontawesome icon in this example. Usage in Twig: {{ eel(node) }}, {{ eel(user) }} or similar.
<?php declare(strict_types=1);
namespace Drupal\my_module;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@drubb
drubb / fix-permissions.sh
Last active February 20, 2024 09:47
Simple script to fix file and directory permissions in Composer based Drupal installation. Suitable if web server and CLI user are members of the same group.
#!/bin/sh
# Exit the script if any statement returns a non-true return value.
set -e
# Goto the project root using Drush
root="$(drush dd)"
cd "$root"
cd ..
@drubb
drubb / parse-media.php
Last active June 7, 2024 09:42
Using a php generator to parse and process Drupal media entities. Executable using drush scr
<?php
use Drupal\media\Entity\Media;
// Get the ids of all media entities.
$media_ids = \Drupal::entityQuery('media')
->accessCheck(FALSE)
->execute();
// Load and process each media entity.