Skip to content

Instantly share code, notes, and snippets.

View JCL324's full-sized avatar

John Learned JCL324

  • CLoud NYNE Design, LLC
  • Portland, OR
View GitHub Profile
@Greg-Boggs
Greg-Boggs / layouts.module.php
Last active November 13, 2022 23:40
layout switcher for Drupal
<?php
function lib_layouts_entity_view_mode_alter(&$view_mode, EntityInterface $entity, $context) {
if ($entity->getEntityTypeId() == 'node' && $entity->bundle() == 'landing_page' && $view_mode == 'full') {
if ($entity->hasField('field_layout')) {
$field = $entity->get('field_layout');
if (!$field->isEmpty()) {
$layout = $entity->get('field_layout')->getString();
$available_modes = \Drupal::service('entity_display.repository')->getViewModes('node');
if (array_key_exists($layout, $available_modes)) {
@StevenGFX
StevenGFX / twig-tweak.md
Last active September 27, 2023 16:11
Twig Tweak Cheat Sheet

View

This accepts views arguments as well:

{{ drupal_view('who_s_new', 'block_1') }}

View with multiple arguments:

{{ drupal_view('who_s_new', 'block_1' 'contextarg1', 'contextarg2', '...') }}

@BBGuy
BBGuy / dc_emw.php
Last active November 16, 2022 14:08
Working with Drupal commerce entities using entity_metadata_wrapper. Just a bunch of exampled copied from the web or added by me. will keep adding over time. now more then just commerce entities
<?php
// Basics
// Get a value.
$value = $wrapper->field_x->value();
// If the field is a reference field you will get the field object
// To get the wrapper back use:
$wrapper_b = $wrapper->field_ref;
// To set a value.