Skip to content

Instantly share code, notes, and snippets.

View DuaelFr's full-sized avatar

Edouard Cunibil DuaelFr

View GitHub Profile
@DuaelFr
DuaelFr / mymodule.php
Last active August 29, 2015 14:20
Translate labels and descriptions without i18n_field
<?php
/**
* Implements hook_field_attach_view_alter().
*/
function MYMODULE_field_attach_view_alter(&$output, $context) {
foreach (element_children($output) as $field_name) {
$element = &$output[$field_name];
if (!empty($element['#entity_type']) && !empty($element['#field_name']) && !empty($element['#bundle'])) {
$instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
@DuaelFr
DuaelFr / fakefacets.js
Created December 16, 2014 11:32
Fake facets JS behavior
(function($) {
Drupal.behaviors.FakeFacets = {
facetClicked: function(event) {
var $source = $(event.srcElement || event.target)
value = $source.data('value'),
$litem = $source.parent()
$list = $litem.parent(),
$wrapper = $list.parent(),
$target = $wrapper.data('target_select');
@DuaelFr
DuaelFr / gist:8820820
Created February 5, 2014 10:30
Extra field with wrappers sample
<?php
/**
* Helper to prepare field renderable array for views extra fields.
*/
function _feature_commons_extra_field_view($field_name, $title, $entity, $view_mode, $langcode, $field_content, $access = TRUE, $entity_type = 'node') {
if (empty($field_content)) {
return '';
}
@DuaelFr
DuaelFr / myprofile.install
Created January 30, 2014 14:07
Enable default language during drupal profile installation
<?php
/**
* @file
* Install, update and uninstall functions for the myprofile installation profile.
*/
/**
* Implements hook_install().
*
* Performs actions to set up the site for this profile.
@DuaelFr
DuaelFr / mymodule.module
Created November 8, 2013 13:35
Set drupal date formats in the code.
<?php
/*
* Implements hook_date_format_types().
*/
function mymodule_date_format_types() {
variable_set('date_format_date_only', 'd/m/Y');
variable_set('date_format_date_only_evt', 'd F Y');
return array(
'date_only' => t('Date only'),
@DuaelFr
DuaelFr / gist:6884247
Created October 8, 2013 12:55
jQuery event resize with timer for performances
function myfunction() {
// Do sth on resize.
}
$(function() {
var intervalId;
$(window).resize(function(e) {
clearTimeout(intervalId);
intervalId = setTimeout(myfunction, 200);
});
<?php if ($main_menu): ?>
<div id="main-menu" class="navigation">
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
@DuaelFr
DuaelFr / gist:6683792
Created September 24, 2013 12:09
Hide drupal tabs using a permission
<?php
/**
* Implements hook_permission().
*/
function MYMODULE_permission() {
return array(
'view contextual tabs' => array(
'title' => t('View contextual tabs'),
'restrict access' => TRUE,
@DuaelFr
DuaelFr / gist:6450482
Last active August 5, 2021 06:12
Download a distant file and save it as a local managed file with drupal.
<?php
/**
* Download a file to the destination and save it into drupal managed files.
*
* @param String $url
* The file to download URL.
* @param String $destination
* The path where the file will be stored. Can be a drupal stream like
* "public://my_dowloads" for example.
@DuaelFr
DuaelFr / mymodule-tip.tpl.php
Last active December 21, 2015 10:19
Static block example in Drupal 7
<a href="<?php echo $link_url; ?>" class="<?php echo $link_class; ?>"><?php echo $link_title; ?></a>