Skip to content

Instantly share code, notes, and snippets.

steffenr / THEMENAME_theme_suggestions_container_alter.php
Created Nov 28, 2019
Custom theme suggestions for container elements in drupal 8
View THEMENAME_theme_suggestions_container_alter.php
* Implements hook_theme_suggestions_alter() for container.
function THEMENAME_theme_suggestions_container_alter(array &$suggestions, array &$variables)
$name = '';
$type = '';
if (isset($variables['element']['#name'])) {
steffenr / hook_update_n.php
Created Aug 20, 2019
Drupal 8 - Batch job in hook_update_n
View hook_update_n.php
use Drupal\node\Entity\Node;
* Implements hook_update_N().
* Set default value to new field field_registered on all Person nodes.
function MY_MODULE_update_8001(&$sandbox) {
steffenr /
Created Feb 4, 2019
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

steffenr / select2_behat_feature_context.php
Last active Sep 13, 2018
Behat / Select2 Feature context
View select2_behat_feature_context.php
* @When /^(?:|I )fill in select2 input "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" and select "(?P<entry>(?:[^"]|\\")*)"$/
public function iFillInSelectInputWithAndSelect($field, $value, $entry)
$page = $this->getSession()->getPage();
$inputField = $page->find('css', $field);
if (!$inputField) {
steffenr / id_map_custom.php
Created Jan 29, 2018
[Drupal 8] Override id map with custom plugin for migrations
View id_map_custom.php
* Implements hook_migration_plugins_alter().
function my_module_migration_plugins_alter(array &$migrations) {
foreach ($migrations as $id => $configuration) {
if (!empty($migrations[$id]['idMap'])) {
// Do not override existing values.
steffenr / expose_author_uid.php
Created Jan 30, 2017
[Drupal8] make user field configurable in comment
View expose_author_uid.php
* Implements hook_entity_base_field_info_alter().
function mymodule_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
switch ($entity_type->id()) {
case 'comment':
$fields['uid']->setDisplayConfigurable('view', TRUE);
steffenr / file_media_entity.php
Last active Sep 4, 2021
[Drupal 8] Create file/ media_entity programmatically
View file_media_entity.php
$filesystem = \Drupal::service('file_system');
// Create file entity.
$image = File::create();
$image->setMimeType('image/' . pathinfo($destination, PATHINFO_EXTENSION));
steffenr / gist:84ba5a5c8bd5af91e20d496e16f05eb3
Created Dec 12, 2016
Determine the size of MySQL databases
View gist:84ba5a5c8bd5af91e20d496e16f05eb3
SELECT table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
steffenr / mymodule.module
Created Aug 15, 2016
Hide fieldset relations in taxonomy term forms for flat hierarchy
View mymodule.module
* Implements hook_form_FORM_ID_alter().
function mymodule_form_taxonomy_my_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Hide fieldset relations for flat hierarchy taxonomies.
$form['relations']['#required'] = FALSE;
$form['relations']['#access'] = FALSE;
steffenr / mymodule.libraries.yml
Created Aug 12, 2016
Attach a CSS or JS library to a View in Drupal 8
View mymodule.libraries.yml
css/custom_view.css: {}