Skip to content

Instantly share code, notes, and snippets.

@jryanconklin
jryanconklin / layout-builder-demo.txt
Last active July 24, 2019 16:46
Data Generated Layout Builder
// theme.layouts.yml
theme_8_4:
label: 'Particle 66:33'
path: templates/layout/theme-8-4
template: theme-8-4
category: 'Columns: 66:33'
default_region: main
icon_map:
- [main, main, aside]
regions:
@johndevman
johndevman / FullNameBlock.php
Last active July 6, 2018 13:40
An example context aware block that combines two fields to be used in Layout Builder
<?php
namespace Drupal\example\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Component\Render\FormattableMarkup;
/**
* Provides the full name of the author of the given node from context.
*
@brooke-heaton
brooke-heaton / merge_ids_during_migration.php
Last active June 29, 2018 17:45
Merge and rename legacy terms based on a mapping on a my_migration.module
<?php
use Drupal\Core\Database\Database;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\MigrateSourceInterface;
/**
* Populate vocab renaming tables from our csv source file with the old name and new name - this
@nathansmith
nathansmith / on_event.js
Last active April 14, 2018 19:31
Event delegation helper.
/*
// Used like so:
onEvent('click', '.foo', (el) => {
// Element that was clicked.
console.log(el)
})
*/
// Event delegation helper.
const onEvent = (event, selector, f) => {
# SPECIFIC: Block #submit #validate #process #pre_render #post_render #element_validate #after_build #value_callback parameters
SecRule REQUEST_FILENAME "(index\.php|\/$)" "chain,id:003294,t:lowercase,t:none,t:utf8toUnicode,t:urlDecodeUni,t:urldecode,block"
SecRule REQUEST_METHOD "^(GET|POST|HEAD)$" chain
SecRule ARGS_NAMES|REQUEST_COOKIES_NAMES "^\#(submit|validate|pre_render|post_render|element_validate|after_build|value_callback|process)$|\[(?:\'|\")?#(submit|validate|pre_render|post_render|element_validate|after_build|value_callback|process)"
# GENERIC: Block all parameters starting with #
SecRule REQUEST_FILENAME "(index\.php|\/$)" "chain,id:003309,t:lowercase,t:none,t:utf8toUnicode,t:urlDecodeUni,t:urldecode,block"
SecRule REQUEST_METHOD "^(GET|POST|HEAD)$" chain
@SteveRyan-ASU
SteveRyan-ASU / redirect-from-json.php
Created January 31, 2018 17:14
Pantheon: Redirect via JSON feed in private file section
// PHP snippet included in wp-config.php (or settings.php).
// Including from that location in a separate file is OK as well.
<?php
// Remove any leading "www." from the host name.
$redirect_host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$redirect_path = strtolower(rtrim($_SERVER['REQUEST_URI']));
if (strlen($redirect_path) > 2) {
$redirect_path = rtrim($redirect_path, '/');
}
@bdlangton
bdlangton / Blocks.md
Last active October 12, 2023 08:40
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@crittermike
crittermike / wget.sh
Last active March 26, 2024 22:49
Download an entire website with wget, along with assets.
# One liner
wget --recursive --page-requisites --adjust-extension --span-hosts --convert-links --restrict-file-names=windows --domains yoursite.com --no-parent yoursite.com
# Explained
wget \
--recursive \ # Download the whole site.
--page-requisites \ # Get all assets/elements (CSS/JS/images).
--adjust-extension \ # Save files with .html on the end.
--span-hosts \ # Include necessary assets from offsite as well.
--convert-links \ # Update links to still work in the static version.
@adeluccar
adeluccar / gist:d105299f2d5af55e3e96f9b989e7eb48
Created August 8, 2017 22:50
How to Flatten the History of a Git Repository Safely
git checkout --orphan future-master
git add -A  # Add all files and commit them
git commit
git branch -D master  # Deletes the master branch
git branch -m master  # Rename the current branch to master
git push -f origin master  # Force push master branch to github
git gc --aggressive --prune=all     # remove the old files