Skip to content

Instantly share code, notes, and snippets.

@opi
opi / gist:2919150
Created June 12, 2012 18:19
Drupal 7 : Programmatically display node_form
$node = (object) array(
'uid' => UID,
'name' => NAME,
'type' => TYPE,
'language' => LANGCODE,
);
$form_state['build_info']['args'] = array($node);
form_load_include($form_state, 'inc', 'node', 'node.pages');
$output = drupal_build_form('TYPE_node_form', $form_state);
@opi
opi / .gitconfig
Last active October 6, 2015 06:07
.gitconfig
[user]
name = YOUR NAME
email = YOUR EMAIL
[color]
ui = true
[color "branch"]
current = yellow reverse
local = yellow
remote = green
@opi
opi / gist:2952877
Created June 19, 2012 07:52
Extreme Drupal CSS aggregation
<?php
/**
* Implements hook_css_alter().
* Force every CSS file on every_page in the same group, in order to have only one aggregated file, and reduce http requests.
*/
function YOURTHEME_css_alter(&$css) {
foreach($css as $file => $info) {
if ($info['type'] == 'file') {
@opi
opi / gist:2952956
Created June 19, 2012 08:14
Extreme Drupal JS aggregation
<?php
/**
* Implements hook_js_alter().
* Force every JS file on every_page in the same group, in order to have only one aggregated file, and reduce http requests.
*/
function YOURTHEME_js_alter(&$js) {
foreach($js as $file => $info) {
if ($info['type'] == 'file') {
$js[$file]['every_page'] = TRUE;
@opi
opi / drushrc.php
Created June 21, 2012 07:18
Drush RC file.
<?php
/**
* Shell Aliases
*/
$options['shell-aliases']['pull'] = '!git pull'; // We've all done it.
$options['shell-aliases']['pulldb'] = '!git pull && drush updatedb';
$options['shell-aliases']['noncore'] = 'pm-list --no-core';
$options['shell-aliases']['wipe'] = 'cache-clear all';
@opi
opi / gist:3247047
Created August 3, 2012 12:15
Drupal: prevent views_load_more to scroll
<?php
/**
* Implements hook_views_ajax_data_alter()
*/
function mymodule_views_ajax_data_alter(&$commands, $view) {
// Do not scroll when using views_load_more module
if ($view->query->pager->definition['handler'] == 'views_plugin_pager_load_more') {
foreach($commands as $k => $command) {
if ($command['command'] == 'viewsScrollTop') {
@opi
opi / gist:3313478
Created August 10, 2012 11:13
Mimic user_edit_access for views page
<?php
// For a view with user/%/foo path
// My module must have a weight greater than views (ex:11)
function mymodule_menu_alter(&$items){
$items['user/%views_arg/foo']['access callback'] = 'mymodule_edit_access';
$items['user/%views_arg/foo']['access arguments'] = array(1);
}
@opi
opi / gist:3359320
Created August 15, 2012 11:26
Drupal jQuery.ui accordion
<?php
drupal_add_library('system', 'ui.accordion');
drupal_add_js('jQuery(document).ready(function(){
jQuery("#wrapper").accordion({
header: ".header",
autoHeight: false,
clearStyle: true,
collapsible: true
});
@opi
opi / gist:3736544
Created September 17, 2012 10:08
Git branch in terminal
#goz git bash
c_cyan=`tput setaf 6`
c_blue=`tput setaf 4`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
@opi
opi / gist:3972431
Created October 29, 2012 08:46
Drsuh commande to update site language domain
<?php
function MYMODULE_drush_command() {
$items = array();
$items['languages-domain'] = array(
'aliases' => array('lang-domain'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap at all.
'options' => array(
'domain' => 'Specify domain (local, dev, prod)',