Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / 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 / 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 / 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;
}
}
<?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;