Skip to content

Instantly share code, notes, and snippets.

View flocondetoile's full-sized avatar

Flocon de toile flocondetoile

View GitHub Profile
@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 / 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 / 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 / ICS.php
Created October 1, 2017 20:33 — forked from jakebellacera/ICS.php
A convenient script to generate iCalendar (.ics) files on the fly in PHP.
<?php
/**
* ICS.php
* =======
* Use this class to create an .ics file.
*
* Usage
* -----
* Basic usage - generate ics file contents (see below for available properties):
@flocondetoile
flocondetoile / extra_field_token.php
Created November 10, 2017 13:30 — forked from opi/extra_field_token.php
Add a sub token for a node field
<?php
/**
* Implements hook_token_info_alter()
*/
function MODULE_token_info_alter(&$data) {
// Modify description of node tokens for our site.
$data['tokens']['node-field_myfield']['foo'] = [
'name' => "Foo",
'description' => "Process field_myfield value"
@flocondetoile
flocondetoile / mailhog.md
Created November 14, 2017 13:29 — forked from opi/mailhog.md
Install and configure MailHog (for Drupal) with a nice systemd unit and apache reverse proxy

MailHog (for Drupal) on Debian Stretch

MailHog is a nice mail testing tool for developers.

Website: https://github.com/mailhog/MailHog

Installation

Download the latest release on your local machine

@flocondetoile
flocondetoile / drupal8.md
Created November 21, 2017 13:31
drupal d8
@flocondetoile
flocondetoile / redis.conf
Created February 1, 2018 01:04 — forked from MaherSaif/redis.conf
Configuration for redis
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
@flocondetoile
flocondetoile / RecurringOrderManager.php
Created June 18, 2018 19:27 — forked from nikathone/RecurringOrderManager.php
Customization for revoking a subscription/Commerce recurring
<?php
namespace Drupal\custom_commerce_recurring;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_recurring\RecurringOrderManager as BaseRecurringOrderManager;
use Drupal\commerce_recurring\RecurringOrderManagerInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
@flocondetoile
flocondetoile / defcontent.sh
Created July 11, 2018 16:17 — forked from DuaelFr/defcontent.sh
Outputs the list of entity types and uuids contained by a content directory of a default_content module
#!/bin/bash
# How to use this script?
#
# 1. create an empty module that depends on default_content or reuse an
# existing one.
# 2. use `drush dcer --folder=path/to/module/content ENTITY_TYPE ID`
# to add default content to your module.
# 3. once all your content is in your module, clean up the content folder
# to only keep the content you need (ie. remove users most of the time).