Skip to content

Instantly share code, notes, and snippets.

View DuaelFr's full-sized avatar

Edouard Cunibil DuaelFr

View GitHub Profile
@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 / 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 / d8test.sh
Last active August 29, 2015 14:22
Script to run simpletests from command line for Drupal 8
#!/bin/bash
RAND=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32)
SQLITE="/mnt/ramdisk/d8test.sqlite.$RAND"
DBURL="sqlite://localhost//mnt/ramdisk/d8test.sqlite.BASE"
URL="http://d8test.sqlite"
CONC=6
if [ $1 ]; then
if [ $1 == "group" ] & [ $2 ]; then
@DuaelFr
DuaelFr / MenuLinkTree.php
Last active May 29, 2018 00:31
Drupal 8 : all menu items always visible
<?php
// File name : my_module/src/Menu/MenuLinkTree.php
/**
* @file
* Contains \Drupal\my_module\Menu\MenuLinkTree.
*/
namespace Drupal\my_module\Menu;
@DuaelFr
DuaelFr / one_line.sh
Created September 4, 2015 23:00
Script to generate patches for updating all drupal core dependencies
cd core; for dep in `composer info -iN`; do composer update $dep; git add -A .; git diff -M --cached > update-dep--${dep//\//--}.patch; git reset HEAD .; git checkout .; git clean -fd .; done; find . -size 0 -name "update-dep--*.patch" -exec rm -r {} \;
@DuaelFr
DuaelFr / MYMODULE.module
Last active September 11, 2015 14:53
Small hook to make field form elements translatables without i18n_field.
<?php
/**
* Implements hook_form_alter().
*
* Allow all field_* form fields title and description to be translated.
*/
function MYMODULE_form_alter(&$form, $form_state) {
foreach (element_children($form) as $key) {
if (strpos($key, 'field_') === 0) {
@DuaelFr
DuaelFr / myprofile.profile
Last active October 4, 2015 23:48
Import local translations when enabling a module.
<?php
/**
* Implements hook_modules_enabled().
*
* Install translations for all modules.
*/
function myprofile_modules_enabled($modules) {
$langs = language_list();
// For each enabled module.
@DuaelFr
DuaelFr / xdebug.ini
Created October 13, 2015 15:21
xDebug config for PhpStorm
[XDebug]
zend_extension = xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port="9000"
xdebug.idekey="PHPSTORM"
xdebug.max_nesting_level=9999
@DuaelFr
DuaelFr / update.sh
Created November 5, 2015 11:00
D8 update
#!/bin/bash
# Get the script's directory.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )
# Go to the document root.
cd $DIR
cd ../www
# Ensure Drupal is already installed.
@DuaelFr
DuaelFr / Controller.php
Created November 6, 2015 11:38
Redirect to the last changed node of a type with elegant cache
<?php
/**
* @file
* Contains \Drupal\faf_videos\Controller.
*/
namespace Drupal\faf_videos;
use Drupal\Core\Cache\Cache;