Skip to content

Instantly share code, notes, and snippets.

View zerolab's full-sized avatar
🖖
Live long and prosper

Dan Braghiș zerolab

🖖
Live long and prosper
View GitHub Profile
@zerolab
zerolab / phpunit_shutdown_function.php
Created June 12, 2017 08:59
PHPUnit: process killed shutdown function to debug
<?php
// PHPUnit dies silently with FATAL ERRORS which
// makes it hard to debug the tests.
// For D8, add this to the end of web/core/tests/bootstrap.php.
//
// @see https://stackoverflow.com/a/33578611/201316
register_shutdown_function('PHPUnit_shutdownFunction');
function PHPUnit_shutdownFunction() {
// @see http://www.php.net/manual/en/errorfunc.constants.php
@zerolab
zerolab / d8_default_user_picture.php
Last active May 11, 2017 10:05
Get default user picture with fallback to theme-provided image
<?php
/**
* Implements hook_preprocess_node().
*
* Example use of mytheme_get_user_picture() for non-standard cases.
* It is probably best to do this in hook_preprocess_user().
*/
function mytheme_preprocess_node(array &$variables) {
/** @var Node $node */
@zerolab
zerolab / instructions.md
Last active May 11, 2017 09:40
Torchbox red flame motd
  1. Save the raw motd as ~/motd
  2. sudo mv ~/motd /etc/motd
  3. Restart terminal
@zerolab
zerolab / example.module.php
Last active March 17, 2017 13:26
Drupal 8 pass data down ER fields
<?php
/**
* @file
* An example of how to pass your custom variable to the first item in a multi-value
* entityreference field.
*/
/**
* Implements hook_preprocess_field().
@zerolab
zerolab / 244-membership-actions.diff
Created March 14, 2017 14:45
OG Membership actions
diff --git a/og/config/schema/og.schema.yml b/og/config/schema/og.schema.yml
index 1bfd4662..3527276e 100644
--- a/og/config/schema/og.schema.yml
+++ b/og/config/schema/og.schema.yml
@@ -160,3 +160,19 @@ field.widget.settings.og_autocomplete:
placeholder:
type: label
label: 'Placeholder'
+
+views.field.og_membership_bulk_form:
@zerolab
zerolab / commands.md
Last active April 19, 2017 09:55
Drupal 8 useful commands

Clear Twig cache

PhpStorageFactory::get('twig')->deleteAll()

e.g. drush ev "\Drupal\Core\PhpStorage\PhpStorageFactory::get('twig')->deleteAll();"

For a particular template

PhpStorageFactory::get('twig')-&gt;delete('path/to/template.html.twig');

@zerolab
zerolab / date_with_user_timezone.php
Created February 21, 2017 14:21
A set of Drupal 8 snippets
<?php
// if you have an account object ($user), then you can use $user->getTimezone().
$timezone = \Drupal::currentUser()->getTimezone();
$given = new \Drupal\Core\Datetime\DrupalDateTime("2016-08-01T12:30:00", $timezone);
$given->setTimezone(new \DateTimeZone("UTC"));
print $given->format("Y-m-d\Th:i:s");
@zerolab
zerolab / menu_link_fields.php
Last active February 21, 2017 11:52
Adds an ER autocomplete field to menu items and renders them in the menu
@zerolab
zerolab / example.md
Last active February 8, 2017 16:34
Drush database import progress
$ brew install pv

-OR-

$ apt-get install pv
@zerolab
zerolab / compact-virtualbox-vm.md
Last active January 26, 2017 14:14
Compact a VirtualBox VM
--------------
Warning: make a copy of the original box. The steps below could lead to an unworkable box.
--------------
  • In the VM cat /dev/zero > fill-me-up;sync;sleep 3;sync;rm -f fill-me-up
  • Shut down the VM
  • On the host (usually in ~/VirtualBox VMs/project_name_UUID/)