Skip to content

Instantly share code, notes, and snippets.

@kerasai
kerasai / xdebug.sh
Created January 25, 2019 12:13
Enables Xdebug CLI to be ran from the CLI
# Run one time, value must match value xdebug.idekey in the PHP config.
export XDEBUG_CONFIG="idekey=123"
export PHP_IDE_CONFIG="serverName=example.local"
# Toggle to enable/disable Xdebug.
export XDEBUG_CONFIG="remote_enable=1"
@kerasai
kerasai / config_install.php
Created January 4, 2019 19:05
Install configuration from YML
<?php
/** @var \Drupal\Core\Config\StorageInterface $config_storage */
$config_storage = \Drupal::service('config.storage');
$path = drupal_get_path('module', 'module_name') . '/config/install';
$file_storage = new \Drupal\Core\Config\FileStorage($path);
$id = 'full.config.identifier';
$config_storage->write($id, $file_storage->read($id));
@kerasai
kerasai / error_reporting.php
Created December 7, 2018 04:04
PHP error reporting
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
@kerasai
kerasai / container.php
Created December 7, 2018 04:03
Create a Symfony Container
<?php
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
// Build the container.
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load('services.yml');
@kerasai
kerasai / repeat.sh
Last active November 29, 2018 17:36
Repeat a migration when it fails due to not enough memory (Drupal, Pantheon, Terminus)
#!/usr/bin/env bash
# Adjust as needed to run desired migration in desired multidev.
SITE_ID=[site_env]
MIGRATION=[migration_id`]
CONTINUE=0
while [ $CONTINUE -eq 0 ]
do
echo "Running migration command..."
@kerasai
kerasai / content_type_rename.sh
Created August 23, 2018 14:21
Renames Drupal content type configuration
# rename files & strip uuids
for f in *.yml; do mv "$f" "$(echo "$f" | sed s/node.experience/node.event/)"; done
for f in *.yml; do sed -i '' -e '/^uuid: /d' "$f"; done
# search/replace contents
for f in *.yml; do sed -i '' -e 's/node\.experience/node\.event/' "$f"; done
for f in *.yml; do sed -i '' -e 's/node\.type\.experience/node\.type\.event/' "$f"; done
for f in *.yml; do sed -i '' -e 's/bundle: experience/bundle: event/' "$f"; done
@kerasai
kerasai / FieldContext.php
Created August 25, 2017 17:48
Behat Context for checking field configuration in Drupal 8
<?php
use Behat\Behat\Context\Context;
/**
* Defines application features from the specific context.
*/
class FieldContext implements Context {
/**
@kerasai
kerasai / EntityReferenceContext.php
Last active July 31, 2017 19:00
Sets and clears values from a Drupal entity reference field widget.
<?php
use Behat\Mink\Mink;
use Behat\MinkExtension\Context\MinkAwareContext;
/**
* Class EntityReferenceContext.
*/
class EntityReferenceContext implements MinkAwareContext {
@kerasai
kerasai / php_error_reporting.php
Last active January 25, 2019 12:09
PHP/Drupal Error Reporting
<?php
# Error reporting.
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set('memory_limit', '64M');
# Drupal mail system to DevelMailLog.
$conf['mail_system'] = array(
@kerasai
kerasai / File Context
Created June 28, 2017 20:52
Behat context for working with files in Drupal 8.
<?php
use Behat\Gherkin\Node\PyStringNode;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Mink;
use Behat\MinkExtension\Context\MinkAwareContext;
/**
* Class FileContext.
*/