Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Drupal\custom_breadcrumbs\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Link;
use Drupal\Core\Url;
@welly
welly / gist:195d9d703707c61b09661220c745fd98
Created January 30, 2024 20:21
Passing attributes between theme hooks
function some_theme_preprocess_paragraph(&$variables) {
$element = &$variables['elements'];
$paragraph = $variables['paragraph'];
if ($paragraph->getType() === 'image_gallery') {
$images = $paragraph->get('field_image_gallery');
foreach ($images->referencedEntities() as $image) {
$image->parent_paragraph = $paragraph;
}
}
@welly
welly / after_update.txt
Last active January 29, 2024 20:13
TimestampFormatterSettingsUpdateTest
Array
(
[uuid] => d0e01c96-4fe9-491d-8a00-f42e3b84465e
[langcode] => en
[status] => 1
[dependencies] => Array
(
[config] => Array
(
[0] => field.field.node.page.body
@welly
welly / my_module.install
Last active January 29, 2024 15:48
Bulk update nodes to enable automatic URL alias generation
<?php
function mymodule_update_9001(&$sandbox) {
// Initialize variables on the first run.
if (!isset($sandbox['total'])) {
$entity_list = \Drupal::entityQuery('node')
->condition('type', 'my_entity')
->execute();
$langcodes = \Drupal::languageManager()->getLanguages();
$sandbox['langcodes'] = array_keys($langcodes);
@welly
welly / example_form.module
Created January 23, 2024 13:37
Adding a custom property to a Config Entity
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\paragraphs\Entity\ParagraphsType;
/**
* Implements hook_form_alter().
*/
function example_form_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_ids = [
@welly
welly / ComboForm.php
Created April 28, 2021 14:46 — forked from Eyal-Shalev/ComboForm.php
An example form object (Drupal 8) that combines multiple forms into itself.
<?php
namespace Drupal\sandbox\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\User;
lando drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name in ('search_api_views_taxonomy');"
@welly
welly / gist:5d0caf2c3d7fe459c4d147f92f8d1254
Created June 29, 2020 12:31
Default Ender 3/Cura start g-code
; Ender 3 Custom Start G-code
G92 E0 ; Reset Extruder
G28 ; Home all axes
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line
G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little
G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
@welly
welly / gist:380539d63e1517c52628f9d5dbb1e8a4
Created February 12, 2019 15:22
Drupal 8: Embedding a view using a render array
$build['view'] = [
'#type' => 'view',
'#name' => 'hero_image',
'#display_id' => 'block_1',
'#arguments' => [
107793,
],
];
@welly
welly / prepare-commit-msg
Created February 12, 2019 11:33
Prepend git commit messages with branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"