Skip to content

Instantly share code, notes, and snippets.

View renebakx's full-sized avatar

René Bakx renebakx

View GitHub Profile
@renebakx
renebakx / tagmanager.php
Created December 16, 2020 09:14
Writing the iframe tag at the top of your html.html.twig file in Drupal 8/9
<?php
function tagmanager_page_top(array &$page_top) {
if (FALSE === \Drupal::service('router.admin_context')->isAdminRoute()) {
$page_top['above'] = [
'#noscript' => true,
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => [
'src' => sprintf('https://www.googletagmanager.com/ns.html?id=%s',$settings->get('gtm_code')),
'height' => 0,
@renebakx
renebakx / drupal8_8.theme.php
Created January 21, 2020 15:21
Re-add views theme suggestions for Drupal 8.8
/**
* Since the patches/fixes for issues
* 2923634 - [PP-1] Use hook_theme_suggestions in views
* 2118743 - [PP-3] Twig debug output does not display all suggestions when an array of theme hooks is passed to #theme
*
* Won't most likely not be in core before D9 lands and frontend developers still rely on those hints being available
* in the twig debug.
*
* You can add this snippet to add them back.
* But be carefull, this version doesn't merge or keep the $suggestions other modules or theme might have added!
# Doesn't show fields to translate
tndt_config.siteconfig:
type: config_object
label: 'Sitewide Configuration'
mapping:
right_text:
type: string
label: 'Text block right'
translatable: true
@renebakx
renebakx / tndt_config.schema.yml
Last active May 8, 2019 06:42
tndt_config.schema.yml
tndt_config.siteconfig:
type: config_object
mapping:
right_text:
type: string
label: 'Text block right'
translatable: true
right_title:
type: string
label: 'Title block right'
@renebakx
renebakx / keybase.md
Created October 11, 2017 08:24
keybase.md

Keybase proof

I hereby claim:

  • I am renebakx on github.
  • I am renebakx (https://keybase.io/renebakx) on keybase.
  • I have a public key ASCmtcme0jjfGgvE66XnuKP7-t0RedQHrzV6D4WTTDzuowo

To claim this, I am signing this object:

@renebakx
renebakx / .bash_profile
Last active September 29, 2017 10:17
switching between project Drush and Drupal, and the global installed
# These two functions asume your are in de public folder of a D8 project
# Run drupal from project when possible
function dpl() {
if [ -f "../vendor/bin/drupal" ]
then
../vendor/bin/drupal "$@";
else
drupal "$@";
fi
@renebakx
renebakx / geocoder.module
Created September 20, 2017 08:31
quick geocoder in D8
<?php
function geocoder_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'node' && $entity->bundle() == 'distributor'){
$street = $entity->get('field_street')->getString();
$city = $entity->get('field_city')->getString();
$country = $entity->get('field_country')->getString();
$adress = sprintf('%s, %s, %s',$street,$city,$country);
$geocode = new Geocode();
@renebakx
renebakx / field.tpl.twig
Created September 7, 2017 12:07
Rendering a single field with multiple items at random in Drupal 8 TWIG
{#
So you have field that can hold 5 images, but you want them to render at random in the frontend?
No problem, get https://www.drupal.org/project/tlh version 8.x-1.6 or higher and use the shuffle filter!
#}
{% for item in items|shuffle %}
{{- item.content -}}
{% endfor %}
{# Be aware of render cache when doing this trick #}
@renebakx
renebakx / uuids.php
Created April 30, 2017 18:06
Laravel 5.4 UUID Trait
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Ramsey\Uuid\Uuid;
trait Uuids {
@renebakx
renebakx / hideme.twig
Created February 16, 2017 10:10
twig trick to hide content without marking it as a comment {# #}
Sometimes you need to implement HTML from a style guide, but commenting out the whole block with {# #} makes it unreadable.
This little 'trick' let's your editor do proper syntax highlighting without showing the HTML in your output
{% if false == true %}
<div class="form-column">
<label for="upload">Your Resumé</label>
<div class="file-upload-field">
<div class="name-display">
<svg class="icon icon-check"><use xlink:href="#icon-check"></use></svg>