Skip to content

Instantly share code, notes, and snippets.

@krisrobinson
krisrobinson / sh_drupal_language.php
Created November 1, 2015 16:34 — forked from dasginganinja/sh_drupal_language.php
Drupal Bulk Language Changer (Uses Views Bulk Options)
$view = new view();
$view->name = 'sh_drupal_languages';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'sh_drupal_languages';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
@krisrobinson
krisrobinson / node.html.twig
Created November 21, 2017 14:35
Drupal 8 node.html.twig snippets
{# Kint
{{ kint(content.field_sections['#items'].getValue()) }}
#}
{# if field is defined
{% if node.field_sections[key].entity.field_section_image.entity.fileuri is defined %}
<img src="{{ node.field_sections[key].entity.field_section_image.entity.fileuri | image_style('large') }}">
{% endif %}
#}
@krisrobinson
krisrobinson / field--paragraph-field--view-mode.html.twig
Created November 21, 2017 14:37
Drupal 8 loop through and print paragraph fields in field.html.twig
<div{{ attributes }}>
{# First check if there is a section video #}
{% for item in items if item.content['#paragraph'].field_section_video is not null %}
{% if loop.first %}
<div{{ item.attributes }}>{{ item.content }}</div>
{% endif %}
{% else %}
{# If no video was found, check if there is a section_image #}
{% for item in items if item.content['#paragraph'].field_section_image is not null %}
{% if loop.first %}
@krisrobinson
krisrobinson / custom.theme.php
Last active December 7, 2022 12:27
Drupal 8 check paragraph bundles and print out view modes in node.hml.twig
<?php
use Drupal\paragraphs\Entity\Paragraph;
/**
* Implements template_preprocess_node
*
* Add variables for paragraphs available to node templates
*/
function CUSTOM_preprocess_node(&$variables) {
// Convenience Variables
@krisrobinson
krisrobinson / ImageUrl.php
Created December 14, 2017 23:45
Thumbnail Image URL Field Formatter for Video Embed Field in Drupal 8
<?php
namespace Drupal\video_embed_field\Plugin\Field\FieldFormatter;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;