Skip to content

Instantly share code, notes, and snippets.

View robdecker's full-sized avatar

Rob Decker robdecker

View GitHub Profile
@robdecker
robdecker / script.js
Last active November 19, 2019 18:18
[JavaScript behavior starter] #d8 #js
(function($, Drupal) {
'use strict';
Drupal.behaviors.nameOfBehavior = {
attach: function (context, settings) {
}
};
@robdecker
robdecker / any
Last active November 2, 2019 02:03
[Rules: on content publish] #d7
{ "rules_on_node_publish" : {
"LABEL" : "On node publish",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "node_presave" ],
"IF" : [
{ "data_is" : { "data" : [ "node:status" ], "value" : "1" } },
{ "AND" : [] },
{ "data_is" : { "data" : [ "node-unchanged:status" ], "value" : "0" } }
],
/**
* Implements hook_menu().
*/
function mymodule_menu() {
$items = array();
$items['admin/config/mymodule'] = array(
'title' => 'My configuration section',
'description' => 'This is the parent item',
'position' => 'left',
'weight' => -100,
@robdecker
robdecker / 1.php
Last active November 2, 2019 02:07
[Views: only display a views attachment of the first page of results] #d7
<?php
function yourmodule_views_post_build($view) {
$view_name = 'the_id_of_the_view';
// The display ID of the main view display.
$display_id = 'page_1';
if ($view->name == $view_name && $view->current_display == $display_id) {
$current_page = $view->get_current_page();
// Hide the attachments on all pages beside the first one.
@robdecker
robdecker / in terminal.md
Last active February 23, 2021 20:59
[Pantheon commands] #d8
@robdecker
robdecker / 1.md
Last active June 18, 2020 22:49
[Patch procedures] #sh #d8 #d7

Applying

Print the results of applying the patch without actually making any changes:

$ patch -p1 --dry-run < fix_scary_module.patch

Apply the patch:

@robdecker
robdecker / .php
Last active November 2, 2019 02:09
[Get Drupal blocks and Context blocks to display elsewhere (ex. in a node.tpl.php)] #d7
<?php
function _mytheme_blocks_by_region($region) {
$context_blocks = array();
$block_blocks = array();
// Blocks that are assigned to the region using Context
if (function_exists('context_get_plugin') && $context = context_get_plugin('reaction', 'block')) {
if ($context_block_list = $context->block_list($region)) {
// Workaround the $context->block_get_blocks_by_region() issue.
@robdecker
robdecker / 1.php
Last active November 2, 2019 02:09
[Using template (.tpl.php) files in your own module] See https://www.drupal.org/node/715160 #d7
<?php
/**
* Implements hook_theme_registry_alter().
*/
function mymodule_theme_registry_alter(&$theme_registry) {
// Defined path to the current module.
$module_path = drupal_get_path('module', 'mymodule');
// Find all .tpl.php files in this module's folder recursively.
$template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path);
@robdecker
robdecker / 1.md
Last active October 19, 2019 20:08
[Common Git commands] #sh #git

Undo last commit

$ git reset HEAD~1

Same as above, but also leave the files staged

$ git reset --soft HEAD~1
@robdecker
robdecker / Gulpfile.js
Last active November 2, 2019 01:45
[Current Gulp setup] #gulp
'use strict';
// Include Gulp
var gulp = require('gulp'),
// Include Plug-ins
changed = require('gulp-changed'),
concat = require('gulp-concat'),
globbing = require('gulp-css-globbing'),
imagemin = require('gulp-imagemin'),