Skip to content

Instantly share code, notes, and snippets.

@opi
opi / gist:4024093
Created November 6, 2012 11:17
Add contextual link to block
<?php
// See http://dominiquedecooman.com/blog/drupal-7-tip-add-contextual-links-anything
// See http://drupal.org/node/1089922
// hook_menu
// Menu item must have 'context' set to MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE
function mymodule_menu() {
return array(
@opi
opi / gist:4024942
Last active October 12, 2017 09:32
Drupal: Add node extra field
<?php
/**
* Implements hook_field_extra_fields().
*/
function mymodule_field_extra_fields() {
// $extra['entity_type']['bundle']
$extra['node']['my_content_type'] = array(
'display' => array(
@opi
opi / gist:4127485
Created November 21, 2012 20:34
Trigger backspace to empty drupal date/hour field
for (var id in Drupal.settings.datePopup) {
$('#'+id).bind('keyup', function(e){
var code = (e.keyCode ? e.keyCode : e.which);
if (code==46 || code==8) {
$(this).val("");
}
})
}
@opi
opi / gist:4170666
Created November 29, 2012 17:39
radio/checkbox parent class
$("[type='radio']").change(function(){
$(this)
.filter(':checked')
.parent().addClass('checked')
.siblings().removeClass('checked')
});
$("[type='checkbox']").change(function(){
if ($(this).checked) {
$(this).parent().addClass('checked')
}
@opi
opi / gist:4193667
Created December 3, 2012 08:34
Drupal: Admin form for file
<?php
function mymodule_admin_image() {
$form = array();
// Image wrapper
$form['image_default'] = array(
'#type'=>'fieldset',
'#title' => "Image par defaut",
'#collapsible' => TRUE,
@opi
opi / gist:4268945
Created December 12, 2012 15:57 — forked from GoZOo/gist:4268937
Drupal: Add class and attributes from custom blocks
/*
* Add class and attributes from custom blocks
*/
function phptemplate_preprocess_block(&$vars) {
if(isset($vars['block']->attributes)) {
if(isset($vars['block']->attributes['class'])) {
$vars['classes_array'] = array_merge($vars['classes_array'], $vars['block']->attributes['class']);
unset($vars['block']->attributes['class']);
}
if(!empty($vars['block']->attributes)) {
<?php
/**
* Implements hook_drush_command().
*/
function custom_local_drush_command() {
$items['files-fix-permissions'] = array(
'description' => 'Fix file permissions',
'aliases' => array('ffp'),
);
@opi
opi / gist:4723213
Created February 6, 2013 15:19
Drupal: Mimic menu_attributes behavior to add a "CSS classes" textfield to menu item form.
<?php
/**
* Implements hook_form_FORM_ID_alter().
*
* Adds menu 'class' attribute options to the edit menu item form.
*/
function mymodule_form_menu_edit_item_alter(&$form, $form_state) {
// Get item
$item = $form['original_item']['#value'];
@opi
opi / gist:5003488
Last active December 14, 2015 01:08
Touch Event, vanilla !
/**
* Touch events
*/
// wrapper is a DOM element
wrapper.touch = {}
wrapper.get(0).ontouchstart = function(e) {
// Store start position
wrapper.touch.x = e.touches[0].clientX;
};
@opi
opi / gist:5133233
Last active December 14, 2015 18:59
theme_field
function _node_view_static_field($field_name, $title, $markup, $weight = 0) {
return array(
'#theme' => "field",
'#weight' => $weight,
'#title' => $title,
'#access' => TRUE,
'#label_display' => "inline",
'#view_mode' => "full",
'#language' => "und",
'#field_name' => $field_name,