Skip to content

Instantly share code, notes, and snippets.

@mootari
mootari / drupalorg-recent-comments.js
Last active December 29, 2017 00:38
TamperMonkey script to display a user's most recent comments on his or her drupal.org profile page.
// ==UserScript==
// @name drupal.org Recent comments
// @namespace https://github.com/mootari/
// @version 0.1
// @description Shows recent comments on a user's profile page
// @include /^https:\/\/www\.drupal\.org\/u\/[^\/]+$
// ==/UserScript==
(function($) {
@mootari
mootari / module.php
Created June 2, 2015 10:20
Handle conflicts between special_menu_items and menu_minipanels. #drupal
<?php
/**
* Implements hook_module_implements_alter().
*
* Ensures that special_menu_items doesn't override menu_minipanels'
* theme_registry_alter implementation.
*/
function MODULE_module_implements_alter(&$implementations, $hook) {
if($hook === 'theme_registry_alter' && isset($implementations['special_menu_items']) && isset($implementations['menu_minipanels'])) {
$value = $implementations['menu_minipanels'];
@mootari
mootari / module.php
Created June 29, 2015 16:50
Scald contexts from image styles feature
<?php
/**
* Implements hook_scald_contexts().
*
* Automatically creates and owns scald contexts from exported image styles.
*/
function MODULE_scald_contexts() {
$func = 'FEATURE_image_default_styles';
<?php
function MODULE_my_form($form, &$form_state) {
// ...
$form['#pre_render'][] = 'MODULE_my_form_add_table';
return $form;
}
function MODULE_my_form_add_table($form) {
@mootari
mootari / module.php
Created August 18, 2015 13:56
Reformat menu options. #drupal #menu
<?php
function MODULE_form_node_form_after_build($form) {
$menu_form = &$form['menu'];
$menu_form = MODULE_node_form_reformat_menus($menu_form);
}
/**
* Reformats parent menu selects.
*/
@mootari
mootari / drupal_debug_schema.php
Created September 15, 2015 09:42
drupal_debug_schema()
<?php
function drupal_debug_schema($module, $table) {
$schema = drupal_get_schema_unprocessed($module);
_drupal_schema_initialize($schema, $module, false);
$dbSchema = Database::getConnection()->schema();
$refMethod = new ReflectionMethod($dbSchema, 'createTableSql');
$refMethod->setAccessible(true);
return $refMethod->invoke($dbSchema, $table, $schema[$table]);
}
@mootari
mootari / module.php
Created September 23, 2015 12:09
Enforcing a URL alias namespace for a node type. #drupal
<?php
function MODULE_form_NODE_TYPE_node_form_alter(&$form, &$form_state, $form_id) {
$prefix = 'PREFIX/';
if(isset($form['path']['alias'])) {
$element = &$form['path']['alias'];
$element['#default_value'] = preg_replace('#^' . preg_quote($prefix) . '#', '', $element['#default_value']);
$element['#field_prefix'] = $prefix;
@mootari
mootari / join_watchdog_users.sql
Last active September 25, 2015 21:01
#drupal
SELECT u.uid user_uid, w.uid admin_uid
FROM watchdog w, users u
WHERE w.type = 'user'
AND w.message LIKE 'New user:%'
AND w.variables REGEXP CONCAT('^a:2:{s:5:"%name";s:[0-9]+:"', u.name, '";');
@mootari
mootari / SassMeister-input.scss
Last active October 26, 2015 13:56
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
$sel-1: (h2, ".fs-h2");
$sel-2: (p, ol, ul);
$extend: unique-id();
@mootari
mootari / plugin.php
Last active October 29, 2015 15:14
Track the current shortcode. #wordpress
<?php
function my_plugin_track_shortcode($name, &$flag) {
global $shortcode_tags;
if(!isset($shortcode_tags[$name])) {
return false;
}
$callback = $shortcode_tags[$name];
$shortcode_tags[$name] = function() use($name, &$flag, $callback) {
$args = func_get_args();