Skip to content

Instantly share code, notes, and snippets.

@GoZOo
GoZOo / route_name.php
Created October 18, 2018 15:17
Drupal 8 - Get route name and parameters from url
// Launch this thanks to /devel/php in your development environment.
$current_path = '/admin/config/';
$url_object = \Drupal::service('path.validator')->getUrlIfValid($current_path);
$route_name = $url_object->getRouteName();
$route_parameters = $url_object->getrouteParameters();
dpm($route_name);
dpm($route_parameters);
@GoZOo
GoZOo / docker-stop-all.sh
Created July 20, 2018 06:06
Script to stop all docker containers
#! /bin/bash
docker stop $(docker ps -a -q)
docker ps
@GoZOo
GoZOo / Debug-Drupal-8-Queries.php
Last active June 17, 2019 12:40
Debug Drupal 8 queries
<?php
// For some queries, use `$query->sqlQuery->` instead of `$query->`.
str_replace(['{', '}'], ['', ''], str_replace(array_keys($query->getArguments()), array_values($query->getArguments()), $query->__toString()));
@GoZOo
GoZOo / drupal8-phpubnit-migration.php
Last active July 28, 2017 12:35
In a Drupal 8 PHPunit migration test, iterate on rows. Warning, if migration is previously executed, no iteration will be made.
<?php
function testMyMigration() {
$migration = $this->getMigration('MY_MIGRATION');
$source = $migration->getSourcePlugin();
$source->initializeIterator();
for ($i=0 ; $i < $source->count(); $i++) {
$source->rewind();
$row = $source->current();
$rows[] = $row;
@GoZOo
GoZOo / FormStatesTest.php
Last active January 19, 2017 11:24
Work in progress to add tests on States attribute of form for Drupal 8
<?php
namespace Drupal\FunctionalJavascriptTests\Form;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests Form #states attribute.
*
* @group Form
@GoZOo
GoZOo / format-json.bash
Last active September 15, 2016 12:01
Command line tool to format large file json and display them in vim
python -mjson.tool < unformatted.json | vim -
@GoZOo
GoZOo / config.yml
Created August 17, 2016 07:54
Config.yml file for drupal-vm vagrant
---
# `vagrant_box` can also be set to geerlingguy/centos6, geerlingguy/centos7,
# geerlingguy/ubuntu1404, geerlingguy/ubuntu1204, parallels/ubuntu-14.04, etc.
vagrant_box: geerlingguy/ubuntu1604
vagrant_user: vagrant
vagrant_synced_folder_default_type: nfs
# If you need to run multiple instances of Drupal VM, set a unique hostname,
# machine name, and IP address for each instance.
vagrant_hostname: drupalvm.dev
@GoZOo
GoZOo / wysiwyg_filter config
Last active August 29, 2015 14:17
Drupal - Configure wysiwyg_filter module
# HTML elements attributes
@[class|style|title|id],
a[href|target<_blank|title],
em/i, strong/b, strike, sub, sup, u, s,
img[width|height|alt|title|src],
p[align<center?justify?left?right],
div[align<center?justify?left?right],
br,address, blockquote, pre, cite, code,
h1,h2,h3,h4,h5,h6,
ul,ol,li,dl,dt,dd,
@GoZOo
GoZOo / xdebug_vagrant
Created February 5, 2015 11:46
Configuration xdebug vagrant
zend_extension=xdebug.so
[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=33.33.33.1
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.max_nesting_level=400
xdebug.idekey=vagrant
@GoZOo
GoZOo / commerce_get_product_display_bundles.php
Last active August 29, 2015 14:14
Drupal Commerce Get all known product displays
<?php
/**
* Get all known product displays.
*
* We know they are product displays if they are node and have
* commerce_product_reference field type.
*
* @return array
* Array of bundle.
*/