Skip to content

Instantly share code, notes, and snippets.

@woombo
woombo / __INDEX.txt
Created December 22, 2016 11:37 — forked from facine/__INDEX.txt
Drupal 8 - Examples
# Taxonomy terms:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_taxonomy_term-php
# Menu links:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_menu_link-php
# File items:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_file-php
# Nodes:
@woombo
woombo / plugin-class-demo.php
Created November 2, 2016 10:57 — forked from thefuxia/plugin-class-demo.php
Plugin Class Demo
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: Plugin Class Demo
* Description: How I am using the base class in plugins.
* Plugin URI:
* Version: 2012.09.29
* Author: Thomas Scholz
* Author URI: http://toscho.de
* License: GPL
* Text Domain: plugin_unique_name
@woombo
woombo / hook_inline_entity_form_table_fields_alter.module
Last active February 11, 2016 18:12
hook_inline_entity_form_table_fields_alter()
/**
* Implements hook_inline_entity_form_table_fields_alter().
*/
function MODULE_inline_entity_form_table_fields_alter(&$fields, $context) {
if ($context['parent_bundle'] === 'MODULE' &&
$context['entity_type'] === 'MODULE_text_asset') {
// Remove Title.
unset($fields['id']);
@woombo
woombo / drupal_content_type_to_taxonomy.php
Created July 27, 2015 17:15
Creates taxonomy every time a content type is saved.
<?php
/*
* Implements hook_node_update().
*/
function openedu_school_node_update($node) {
if ($node->type == 'school' && isset($node->field_school_category['und'][0]['tid'])) {
$term = taxonomy_term_load($node->field_school_category['und'][0]['tid']);
$term->name = $node->title; //change existed taxonomy term
taxonomy_term_save($term);
@woombo
woombo / xdebug
Created July 15, 2015 22:04
xdebug
xdebug.max_nesting_level=256
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
;xdebug.profiler_enable=0
;xdebug.profiler_output_dir="/Applications/MAMP/tmp"
zend_extension="/Applications/MAMP/bin/php/php5.5.17/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
@woombo
woombo / gist:254e0a6f188236fccd7f
Created June 5, 2015 18:47
Drupal Features: Allow custom view templates to be placed within feature
<?php
/**
* Implements hook_views_api_alter().
* Alter the list of modules/themes which implement a views api.
*/
function MODULE_views_api_alter(&$list) {
// Alter the path of the views implementation.
if (isset($list['MODULE'])) {
$path = drupal_get_path('module', 'MODULE');
$list['MODULE']['path'] = $path;
dependencies[] = ctools
; Views Handlers
files[] = views/mymodule_handler_handlername.inc
@woombo
woombo / Enforce array on an object
Created April 10, 2015 20:16
Enforce array on an object
<?php
// Enforce all rows are converted to an array when needed.
$rows = json_decode(json_encode($endpoints), TRUE);
# http://www.millwoodonline.co.uk/blog/drupal-cron-failing-not-sure-why-heres-handy-drush-command
drush php-eval ' global $timers; $hook = 'cron'; $return = array(); foreach (module_implements($hook) as $module) { $function = $module . '_' . $hook; print($function ." - "); timer_start($function); $args = array(); $result = call_user_func_array($function, $args); if (isset($result) && is_array($result)) { $return = array_merge_recursive($return, $result); } else if (isset($result)) { $return[] = $result; } timer_stop($function); print($timers[$function]['time'] ."\r\n"); }'
@woombo
woombo / mymodule.md
Last active September 21, 2016 17:15 — forked from juampynr/mymodule.md

This document contains a common database updates in Drupal 7 projects.

Change a field type from textarea to textfield (wipe out its data)

Let's suppose we want to change field_article_summary from text to textarea, but we do not care about loosing its current data.

Start by removing the field through the Admin Interface in your local environment. Then, add the field with the new configuration and recreate the feature where it was exported. Finally, add the following database update: