Skip to content

Instantly share code, notes, and snippets.

View flocondetoile's full-sized avatar

Flocon de toile flocondetoile

View GitHub Profile
@flocondetoile
flocondetoile / NodeIndexNid.php
Created September 29, 2017 14:04 — forked from StryKaizer/NodeIndexNid.php
Exposed filters for entity references -> nodes. Port from TaxonomyIndexTid.php
<?php
namespace Drupal\yourmodule\Plugin\views\filter;
use Drupal\Core\Entity\Element\EntityAutocomplete;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\Entity\Node;
use Drupal\node\NodeStorageInterface;
use Drupal\views\ViewExecutable;
@flocondetoile
flocondetoile / drupal_multiple_field_add_to_top.php
Created May 11, 2017 14:17 — forked from opi/drupal_multiple_field_add_to_top.php
Drupal multiple field : Add new item on top of the list
<?php
// Insert new item on top of the list.
// Display file input first for better UI (https://lut.im/0AkZwIQOUa/dtzEPerqgp3hQ3hk.png)
// In a .module
/**
@flocondetoile
flocondetoile / hide_untranslated.php
Created February 3, 2017 10:51 — forked from filipengberg/hide_untranslated.php
Drupal 8 module that hides entities that has no translation in the currently viewed language. Also redirects untranslated node views to frontpage
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Url;
/**
@flocondetoile
flocondetoile / Flip.css
Created November 18, 2016 20:14 — forked from smockle/Flip.css
Flip demonstrates a flip animation using CSS. Tested in Google Chrome 26, IE 10, and Firefox Nightly.
/* entire container, keeps perspective */
body .flip-container {
width: 100%;
}
body .flip-container .flipper {
position: relative;
}
/* hide back of pane during swap */

Installation d'Apache Solr sur Debian Jessie (pour Drupal 7)

Il semble assez courant d'utiliser le moteur d'indexation Apache Solr pour Drupal via la panoplie de module autour de Search API.

Mais installer Solr n'est pas aussi simple qu'installer un module Drupal. Voici donc un guide d'installation, basé sur Debian Jessie.

Pré-requis

Apache Solr en développé en Java, il nous faut donc installer la plateforme d'execution JRE (Java Runtime Environment).

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'];
}
}
}
@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.
@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 / 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 / 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',