Skip to content

Instantly share code, notes, and snippets.

@steffenr
steffenr / mymodule.module
Created August 15, 2016 10:01
Hide fieldset relations in taxonomy term forms for flat hierarchy
<?php
/**
* 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
steffenr / mymodule.libraries.yml
Created August 12, 2016 11:40
Attach a CSS or JS library to a View in Drupal 8
custom_view:
css:
component:
css/custom_view.css: {}
@steffenr
steffenr / themename.info.yml
Created August 11, 2016 18:07
Embed external fonts in Drupal 8 theme (fonts are added in custom themename.libraries.yml)
name: Theme name
type: theme
description: Theme description
package: Custom
core: 8.x
libraries:
- themename/fonts
- themename/global-styling
base theme: classy
@steffenr
steffenr / pseudo_field_node_edit.php
Last active August 3, 2016 18:19
Add pseudo field to node edit form (works fine in combination with field_group module)
<?php
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'node_article_edit_form') {
$form['my_view'] = [
'#markup' => 'Some arbitrary markup.',
];
// Access entity object.
@steffenr
steffenr / cleanup.sh
Last active March 21, 2016 13:56
Clean up all git branches except 'develop'
git branch | grep -v "develop" | sed 's/^[ *]*//' | sed 's/^/git branch -d /' | bash
@steffenr
steffenr / custom.links.action.yml
Last active December 9, 2015 09:25
Custom local actions with route_parameters #drupal8
@steffenr
steffenr / route_name.php
Last active July 1, 2017 21:53
Get current route name based on request in drupal 8.
<?php
$route_name = \Drupal::service('current_route_match')->getRouteName();
?>
@steffenr
steffenr / url.php
Last active March 24, 2016 10:51
Create link with attributes in Drupal 8
<?php
$link_url = Url::fromRoute('node.add', array('node_type' => $content_type));
$link_url->setOptions(array(
'attributes' => array(
'class' => array('button')
),
'query' => \Drupal::destination()->getAsArray(),
));
$link_text = t('Add !content_type content', array('!content_type' => ucfirst($content_type)));
// Build link
@steffenr
steffenr / extract_db_tables.sh
Last active November 2, 2015 19:28
Extract single table from mysql dump
# Extract CREATE / INSERT from default mysql dump.
zcat > dump.sql.gz | sed -n -e '/CREATE TABLE.*`my_table`/,/UNLOCK TABLES/p' > my_table.sql
# Extract INSERTs only.
zcat > dump.sql.gz | sed -n -e '/INSERT INTO `my_table`/,/UNLOCK TABLES/p' > my_table.sql
@steffenr
steffenr / leaflet_markercluster.drupal.js
Created January 27, 2015 18:29
Fix not working leaflet markercluster spidering in drupal - overwrite leaflet_markercluster via hook_js_alter in custom module
/*
* We are overriding a large part of the JS defined in leaflet (leaflet.drupal.js).
* Not nice, but we can't do otherwise without refactoring code in Leaflet.
*/
(function ($) {
var LEAFLET_MARKERCLUSTER_EXCLUDE_FROM_CLUSTER = 0x01;
Drupal.behaviors.leaflet = { // overrides same behavior in leaflet/leaflet.drupal.js