Skip to content

Instantly share code, notes, and snippets.

View DuaelFr's full-sized avatar

Edouard Cunibil DuaelFr

View GitHub Profile
@DuaelFr
DuaelFr / mymodule.module
Created December 31, 2015 11:13
Drupal GET form without tokens/op in one function.
<?php
function mymodule_myform($form, $form_state) {
$form = [
'#method' => 'GET',
'#action' => url('my_search_page'),
'#token' => FALSE,
'#after_build' => [
function($form) {
$form['form_token']['#access'] = FALSE;
@DuaelFr
DuaelFr / MyBreadcrumbBuilder.php
Last active March 22, 2016 11:02
D8 breadcrumb following menus
<?php
/**
* @file
* Contains \Drupal\mymodule\MyBreadcrumbBuilder.
*/
namespace Drupal\mymodule;
use Drupal\Core\Breadcrumb\Breadcrumb;
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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