Skip to content

Instantly share code, notes, and snippets.

View DuaelFr's full-sized avatar

Edouard Cunibil DuaelFr

View GitHub Profile
@DuaelFr
DuaelFr / feature_commons.module
Created January 19, 2017 09:05
Disable page title from a paragraph setting
<?php
/**
* Helper to hide the page title (see THEME_preprocess_page).
*/
function _feature_commons_hide_title($value = NULL) {
$static = &drupal_static(__FUNCTION__, FALSE);
if (NULL !== $value) {
$static = (bool) $value;
}
@DuaelFr
DuaelFr / my_module.module
Last active January 9, 2017 11:37
Preset paragraph on node creation
<?php
use Drupal\node\Entity\Node;
/**
* Implements hook_ENTITY_TYPE_create().
*/
function my_module_node_create(Node $node) {
if ($node->bundle() == 'my_bundle') {
$field = $node->get('field_my_paragraph_field');
@DuaelFr
DuaelFr / d8test.sh
Created December 9, 2016 13:43
Script to launch D8 tests
#!/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 / my_module.install
Created October 21, 2016 14:14
Bean creation on install
/**
* Implements hook_install().
*/
function my_module_install() {
$bean = bean_create(array('type' => 'simple'));
$bean->label = 'Mon bloc simple custom';
$bean->title = '';
$bean->delta = 'my-delta';
$bean->field_content = array(
LANGUAGE_NONE => array(
// Declaration globale.
window.MonHelper = {
function1: function (context, settings) { alert("truc de base"); }
};
(function ($, Drupal) {
"use strict";
Drupal.behaviors.TrucDuCore = {
attach: function (context, settings) {
@DuaelFr
DuaelFr / d8test.sh
Created June 22, 2016 13:43
Launch tests on D8 using cli
#!/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 / MYMODULE.module
Created March 29, 2016 10:58
D8 menu item expanded by default
/**
* Implements hook_ENTITY_TYPE_presave().
*
* Force the expanded state on menu items in the main menu.
*/
function MYMODULE_menu_link_content_presave(MenuLinkContentInterface $entity) {
if ($entity->get('menu_name')->value == 'main') {
$entity->get('expanded')->set(0, TRUE);
}
}
@DuaelFr
DuaelFr / Controller.php
Last active March 14, 2017 12:19
Guzzle Oauth current state
<?php
/**
* @file
* Contains \Drupal\sf_test\Controller\DefaultController.
*/
namespace Drupal\sf_test\Controller;
use Drupal\Core\Controller\ControllerBase;
@DuaelFr
DuaelFr / anywhere.php
Created February 10, 2016 10:58
D8 Taxonomy tree to nested HTML list
<?php
$vocabulary_name = 'my_machine_name';
$root_tid = 0;
$vocabulary = $this->vocabularyStorage->load($vocabulary_name);
$terms = $this->termStorage->loadTree($vocabulary->id(), $root_tid);
$tree = [$root_tid => []];
foreach ($terms as $term) {
$tree[$term->tid] = [
@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;