Skip to content

Instantly share code, notes, and snippets.

View flocondetoile's full-sized avatar

Flocon de toile flocondetoile

View GitHub Profile
/**
* Implements hook_theme().
*/
function uas_paragraphs_theme() {
return array(
'paragraph__paragraph_imagetext' => array(
'render element' => 'elements',
'base hook' => 'paragraph',
),
);
$blockConfig = \Drupal::languageManager()->getLanguageConfigOverride('en', 'block.block.follow_us');
$blockConfig->set('settings', ['label' => 'Follow us'])->save();
/**
* Implements hook_preprocess_HOOK().
*/
function mymodule_preprocess_menu(&$variables) {
if ($variables['menu_name'] == 'main') {
$variables['terms_list'] = views_embed_view('name_view', 'name_display');
}
}

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).

@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 */
function MYTHEME_preprocess_field__block_content__tabs_block(&$variables){
$variables['entity_reference_target_type'] = $variables['element']['#items']->getItemDefinition()->getSetting('target_type');
$block_uuid = $variables['element']['#object']->toArray()['uuid'][0]['value'];
$blocks = $variables['element']['#items']->referencedEntities();
if (isset($blocks)) {
foreach ($blocks as $key => $block) {
$variables['items'][$key]['block_data']['label'] = $block->label();
if (!empty($block_uuid)) {
$variables['items'][$key]['block_data']['id'] = $block_uuid."-".$key;
} else {
@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;
/**
// inside an event subscriber of `OrderEvents::ORDER_UPDATE` (edited)
if ($order->getState()->value == 'completed' && $order_total = $order->getTotalPrice()) {
$original_order = $order->original;
if ($original_order && $order->getState()->value == 'draft') {
/** @var \Drupal\commerce_payment\PaymentStorageInterface $payment_storage */
$payment_storage = \Drupal::entityTypeManager()->getStorage('commerce_payment');
$payments = $payment_storage->loadMultipleForOrder($order);
if ($payments) {
$payments_total= new Price(0, $order_total->getCurrencyCode());
@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
/**
/**
* Implements hook_entity_base_field_info().
*
* - Provides a base field that displays the current workflow state on nodes.
* This field is intended to be used to expose this information.
*/
function state_machine_workflow_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
/** @var \Drupal\state_machine_workflow\WorkflowHelper $workflowHelper */