Skip to content

Instantly share code, notes, and snippets.

@waako
waako / gulpfile.js
Created February 20, 2017 18:07
Gulpfile.js v4
var gulp = require('gulp'),
fs = require('fs'),
path = require('path'),
naturalSort = require('gulp-natural-sort'),
browserSync = require('browser-sync'),
cp = require('child_process'),
rsync = require('gulp-rsync'),
rev = require('gulp-rev'),
del = require('del'),
collect = require('gulp-rev-collector'),
@waako
waako / .csscomb.json
Created January 19, 2017 15:51
Gulp workflow for Drupal 8 theme. Includes csscomb for Drupal CSS Code Standards and Sass Lint
{
"exclude": [
".git/**",
"misc/**",
"modules/**",
"profiles/**",
"themes/**",
"node_modules/**",
"bower_components/**"
],
@waako
waako / configuration.yaml
Created November 19, 2016 21:05
Home Assistant config for Emon stuff
homeassistant:
# Name of the location where Home Assistant is running
name: emonPi Demo
# C for Celcius, F for Fahrenheit
temperature_unit: C
# Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
time_zone: Europe/London
# Location required to calculate the time the sun rises and sets
latitude: 56.14286
longitude: -4.15401
@waako
waako / themename.theme.php
Last active October 6, 2016 10:59
Drupal 8 Block and Menu template suggestions
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function THEMENAME_theme_suggestions_block_alter(array &$suggestions, array $variables) {
$block_id = $variables['elements']['#id'];
// See if block ID contains the word mobile.
$is_mobile_block = strpos($block_id, 'mobile');
$block = \Drupal\block\Entity\Block::load($block_id);
@waako
waako / themename.theme.php
Last active August 31, 2016 20:30
Get value of field from a node inside region
<?php
/**
* Implements hook_preprocess_HOOK() for region templates.
*/
function themename_preprocess_region__region_name(&$variables) {
// Check if current page is a node.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
// Check if node has the field site_section.
if ($node->hasField('field_site_section')) {
@waako
waako / .htaccess
Created July 14, 2016 15:16
redirect all traffic to https, except one page, and ensure that page is served on http
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/who-we-are/careers$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Ensure that Careers page is not forced over HTTPS
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/who-we-are/careers$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@waako
waako / themename.theme.php
Created June 19, 2016 16:48
Drupal 8: get a block's parent node title and absolute url and pass it as variable
<?php
/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*/
function themename_preprocess_block(&$variables) {
// Get Title of Block's parent Node.
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
@waako
waako / theme.php
Created June 3, 2016 12:11
Drupal Paragraphs get image url with image style
<?php
use Drupal\image\Entity\ImageStyle;
/**
* Implements hook_preprocess_HOOK() for paragraph--para-slide.html.twig.
*/
function themename_preprocess_paragraph__para_slide(&$variables) {
$paragraph = $variables['paragraph'];
if (!$paragraph->field_image->isEmpty()) {
@waako
waako / node.twig
Last active May 26, 2016 14:08
Calling ImageStyle throws error when content type has a file field: Cannot use object of type Drupal\node\Entity\Node as array in theme.theme on line 12
<div style="background-image:url('{{ hero_image_url }}');">
This has a background image
</div>
@waako
waako / themename.theme.php
Last active June 17, 2019 12:54
Drupal 8: Get Block's parent Node title and full URL
<?php
use Drupal\Core\Url;
/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*/
function themename_preprocess_block(&$variables) {
// Get Title of Block's parent Node.
$request = \Drupal::request();