Skip to content

Instantly share code, notes, and snippets.

View flocondetoile's full-sized avatar

Flocon de toile flocondetoile

View GitHub Profile
@flocondetoile
flocondetoile / gist:8e1d77dbb6d402540bd9
Created October 27, 2015 17:04 — forked from opi/gist:6078227
Simple social links extra_field for drupal.
<?php
// Social share links
$links = array();
$share_url = url('node/'.$node->nid, array('absolute' => TRUE));
$links['facebook'] = array(
'href' => 'https://www.facebook.com/sharer/sharer.php?u='.$share_url,
'title' => t("Facebook"),
'attributes' => array(
'data-popup-width' => 700,
<!-- Placer ce code directement après l'ouverture du <body> -->
<!--[if lte IE 9]>
<p class="browsehappy">Vous utilisez un navigateur <strong>dépassé</strong>. Merci de <a href="http://browsehappy.com/">mettre à jour votre navigateur</a> pour améliorer votre expérience sur ce site.</p>
<![endif]-->
@flocondetoile
flocondetoile / gist:9091f66cd3fe1a39ded3
Created January 14, 2016 22:52 — forked from opi/gist:8470954
Drupal 7 Search language and content type
<?php
/**
* Implements of hook_query_node_access_alter().
*/
function MYMODULE_query_node_access_alter(QueryAlterableInterface $query) {
$search = FALSE;
$node = FALSE;
foreach ($query->getTables() as $alias => $table) {
@flocondetoile
flocondetoile / gist:0a0950e56e53683e37fe
Created January 14, 2016 22:55 — forked from opi/gist:6164121
Drupal: tabbed block with jQuery UI
<?php
function my_module_my_tabbed_block() {
// Block title
$block['subject'] = t("My tabbed block");
// Tabs.
$block['nav'] = array(
'#theme' => 'item_list',
/**
* Implements hook_theme_registry_alter().
*/
function my_module_theme_registry_alter(&$theme_registry) {
$theme_registry['paragraph__paragraph_citation'] = $theme_registry['paragraph'];
$theme_registry['paragraph__paragraph_citation']['theme path'] = drupal_get_path('module', 'my_module');
$theme_registry['paragraph__paragraph_citation']['template'] = 'paragraph--paragraph-citation';
$theme_registry['paragraph__paragraph_citation']['path'] = drupal_get_path('module', 'my_module') . '/templates';
@flocondetoile
flocondetoile / MyBreadcrumbBuilder.php
Created March 22, 2016 11:02 — forked from DuaelFr/MyBreadcrumbBuilder.php
D8 breadcrumb following menus
<?php
/**
* @file
* Contains \Drupal\mymodule\MyBreadcrumbBuilder.
*/
namespace Drupal\mymodule;
use Drupal\Core\Breadcrumb\Breadcrumb;
@flocondetoile
flocondetoile / mymodule.module
Created March 23, 2016 12:06 — forked from DuaelFr/mymodule.module
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;
@flocondetoile
flocondetoile / README.md
Created May 25, 2016 11:03 — forked from juampynr/README.md
Sample Guzzle 6 request to Drupal 8 using OAuth 1

This script helps you to test OAuth-signed requests against Drupal 8.

First, make sure that Drupal has been configured by following the steps at https://www.drupal.org/node/2110825. Then install this script with these steps:

  1. Clone this gist.
  2. Run composer.install.
  3. Open oauth_request.php and fill out your consumer_key and consumer_secret. Then Adjust base_uri.
  4. Execute the script with php oauth_request.php.
/**
* @param string $type
* @param string $title
* @param string $langcode
* @param string $uid
* @param array $fields
* @param bool $promote
* @param bool $status
* @return \Drupal\node\Entity\Node $node
*/
function my_module_entity_view(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
if ($entity instanceof FieldableEntityInterface && $entity->hasField('field_name')) {
foreach (Element::children($build['field_name']) as $item) {
$build['field_name'][$item]['#attributes'] = ['class' => 'my-class'];
}
}
}