Skip to content

Instantly share code, notes, and snippets.

View Berdir's full-sized avatar

Sascha Grossenbacher Berdir

View GitHub Profile
<?php
/**
* This plugin creates a new paragraph entity based on the source.
*
* @MigrateProcessPlugin(
* id = "mds_paragraph"
* )
*/
class ParagraphMigrateProcessor extends ParagraphProcessBase {
@Berdir
Berdir / gist:0909a0bb17019b7cf4b5
Created May 21, 2015 17:30
commit all modules in separate commits
for module in `ls`; do git add -A $module; git commit -m "Updated $module"; done
@Berdir
Berdir / gist:3bfdb91e664e325004ba
Created April 30, 2015 09:43
Update redirect source fields
/**
* Update the {redirect} table.
*/
function np8_update_update_8004() {
// Drop the title column.
if (db_field_exists('redirect', 'redirect_source__title')) {
db_drop_field('redirect', 'redirect_source__title');
}
// We assume there are no options stored and just rename it to query.
if (db_field_exists('redirect', 'redirect_source__uri')) {
diff --git a/core/lib/Drupal/Core/Form/FormCache.php b/core/lib/Drupal/Core/Form/FormCache.php
index a35000d..6ddcccc 100644
--- a/core/lib/Drupal/Core/Form/FormCache.php
+++ b/core/lib/Drupal/Core/Form/FormCache.php
@@ -212,8 +212,40 @@ public function setCache($form_build_id, $form, FormStateInterface $form_state)
$form_state->addBuildInfo('safe_strings', SafeMarkup::getAll());
if ($data = $form_state->getCacheableArray()) {
+ $this->traceMe($data);
$this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id, $data, $expire);
@Berdir
Berdir / config.nice
Last active September 21, 2015 02:21
php 7 config.nice
#! /bin/sh
#
# Created by configure
'./configure' \
'--prefix=/home/berdir/binaries/php7' \
'--with-config-file-path=/home/berdir/binaries/php7' \
'--enable-mbstring' \
'--enable-zip' \
'--enable-bcmath' \
@Berdir
Berdir / cacheget.php
Created April 8, 2015 21:34
cache benchmark
<?php
use Drupal\Component\Utility\SafeMarkup;
$cache = \Drupal::cache();
$before = $start = microtime(TRUE);
for ($i = 1; $i < 500000; $i++) {
$cache->get('cache_bench_test_' . $i);
if ($i % 10000 == 0) {
<?php
/**
* Minifies and removes unneeded cache tags.
*
* @param array $cache_tags
* List of cache tags.
*
* @return array
* Shortened and cleaned up cache tag list.
@Berdir
Berdir / schema.yml
Last active August 29, 2015 14:16 — forked from aneek/schema.yml
# Defines the schema to store each connection entry.
sso_connect.connection.* :
type: config_entity
label: SSO connection
mapping:
name:
type: label
label: 'Name'
id:
@Berdir
Berdir / gist:9d8739e5962a227dfdae
Created February 20, 2015 18:30
new csrf token is not saved after a session regenerate/login
// Dark magic from the darkest pits of drupal. After a session regenerate,
// the metadata session bag and $_SESSION are no longer in sync and updates in
// there are not reflected. A new token seed is generated when the form is
// cached, but then not persistend and the form cache token validation fails.
// Manually copy the token seed into $_SESSION.
$metadata = \Drupal::service('session_manager.metadata_bag');
$_SESSION['_sf2_meta'][$metadata::CSRF_TOKEN_SEED] = $metadata->getCsrfTokenSeed();
@Berdir
Berdir / TagDeletionListener.php
Last active July 21, 2021 23:11
Varnish cache tag purger
<?php
/**
* @file
* Contains \Drupal\varnish_cache_tag_purger\TagDeletionListener.
*/
namespace Drupal\varnish_cache_tag_purger;
use Drupal\Core\Cache\NullBackend;