Skip to content

Instantly share code, notes, and snippets.

@mootari
mootari / README.md
Last active August 29, 2015 14:17
CKEditor for drupal.org issues

Instructions

To create your own custom bookmarklet, do the following:

  1. Visit http://chriszarate.github.io/bookmarkleter/

  2. Leave the checkboxes in their default state.

  3. Paste the following Javascript code:

     (function(){jQuery.getScript("https://rawgit.com/cisso/529d08f9a006358de96e/raw/script.js", function(){
    

D_ORG_CKEDITOR.replace("summary");

cask 'adium'
cask ’adium’
@mootari
mootari / git-match-patch
Last active August 29, 2015 14:17
Attempts to find the commit a patch applies to cleanly. Usage: git-match-patch {branch} {patch-file}
#!/bin/bash
current=$(git rev-parse HEAD)
commits=$(git rev-list $1)
for rev in $commits; do
git checkout --quiet $rev
git apply --check $2 2>/dev/null
if [ $? == 0 ]; then
git log -n 1
exit 0
fi
@mootari
mootari / paragraphs_disable_drag_add.php
Last active August 29, 2015 14:18
Example on how to prevent reordering of paragraphs field forms (and other forms) #drupal #form-api #tabledrag
<?php
/**
* Removes item sort/add/remove capabilities.
*
* When called on an element during hook_field_attach_form(), this function
* ensures that no item can be added, removed or reordered.
* Currently adjusted to paragraphs. The core MV widget may required different
* button keys.
*/
function EXAMPLE_lock_paragraphs_multiple_value_form(&$element) {
@mootari
mootari / cleanup_field_values.php
Last active August 29, 2015 14:18
Delete entity translation leftovers (field values in languages other than the node language that are not LANGUAGE_NONE).
<?php
function EXAMPLE_cleanup_field_values($node_type = null) {
$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'node');
if($node_type) {
$query->entityCondition('bundle', $node_type);
}
$results = $query->execute();
if(empty($results['node'])) {
return;
@mootari
mootari / build_menu_tree.php
Last active August 29, 2015 14:19
Renders a Drupal submenu tree without using menu_block. #drupal-7 #menu-tree
<?php
/**
* Renders a submenu tree.
*
* @param string $menu
* The internal menu name
* @param string $path
* The path. May be an alias.
* @return array
* Menu tree render array
<?php
/**
* Performs authentication and returns required headers.
*/
function EXAMPLE_post_authenticate($endpoint_url) {
$user_login = array(
'name' => 'username',
'pass' => 'password'
);
@mootari
mootari / features_fix_node_type_cache.php
Last active August 29, 2015 14:20
To be called from hook_install()
/**
* Fixes an issue with node type permissions in features.
*
* Temporarily implements hook_module_implements_alter().
* Temporarily implements hook_modules_enabled().
*
* When a node type feature gets enabled, the node type
* cache does not get regenerated immediately.
* This causes node type specific permissions to be missing
* when subsequent features are enabled that set
@mootari
mootari / exposed_facets.php
Last active August 29, 2015 14:21
Inject facet block in views exposed form
<?php
function MODULE_get_exposed_facet_token($delta) {
return "<!-- FACET:$delta -->";
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function MODULE_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
@mootari
mootari / preprocess_suggestions.php
Created May 20, 2015 21:05
Preprocessing for theme hook suggestions. #drupal #theme
<?php
/**
* Provides additional preprocess hooks for theme hook suggestions.
*/
function _THEME_process_hooks(&$vars, $process = 'preprocess', $hooks = null) {
$prefix = '_THEME';
if(is_null($hooks)) {