Skip to content

Instantly share code, notes, and snippets.

View Elendev's full-sized avatar

Jonas Renaudot Elendev

View GitHub Profile
@Elendev
Elendev / AdminMenuSubscriber.php
Created April 16, 2019 08:35
Sylius - add an On Hold state
<?php
// file src/EventSubscriber/AdminMenuSubscriber.php
namespace App\EventSubscriber;
use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent;
use Sylius\Component\Core\OrderPaymentStates;
use Sylius\Component\Core\OrderShippingStates;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@Elendev
Elendev / Drupal.d.ts
Created May 15, 2018 12:33
Medium : Drupal 8, Typescript, React and i18n
declare namespace Drupal {
/**
* Helper to rethrow errors asynchronously.
*
* This way Errors bubbles up outside of the original callstack, making it
* easier to debug errors in the browser.
*
* @param {Error|string} error
* The error to be thrown.
@Elendev
Elendev / locale.module
Last active May 15, 2018 08:47
Medium : Drupal 8, Typescript, React and i18n - locale.module
/**
* Implements hook_js_alter().
*/
function locale_js_alter(&$javascript, AttachedAssetsInterface $assets) {
// ...
// Replace the placeholder file with the actual JS translation file.
$placeholder_file = 'core/modules/locale/locale.translation.js';
if (isset($javascript[$placeholder_file])) {
@Elendev
Elendev / locale.libraries.yml
Created May 14, 2018 11:59
Medium : Drupal 8, Typescript, React and i18n - locale.libraries.yml
translations:
# No sensible version can be specified, since the translations may change at
# any time.
js:
# This file does not actually exist; it's a placeholder file that will be
# overriden by locale_js_alter(), to use the file that contains the actual
# translations, for the language used in the current request.
locale.translation.js: {}
@Elendev
Elendev / Drupal.t.js
Last active May 14, 2018 12:07
Medium : Drupal 8, Typescript, React and i18n - Drupal.t.js
Drupal.t = function (str, args, options) {
options = options || {};
options.context = options.context || '';
if (typeof drupalTranslations !== 'undefined' && drupalTranslations.strings && drupalTranslations.strings[options.context] && drupalTranslations.strings[options.context][str]) {
str = drupalTranslations.strings[options.context][str];
}
if (args) {
str = Drupal.formatString(str, args);