Skip to content

Instantly share code, notes, and snippets.

View rvizena's full-sized avatar

rvizena

View GitHub Profile
@rvizena
rvizena / oog_email_formatter.info
Created August 20, 2018 23:02
D7 email formatter to hide address
name = Oog Email Formatter
description = Replaces actual email address with the word "email"
core = 7.x
@rvizena
rvizena / import.php
Created February 28, 2020 18:50 — forked from crittermike/import.php
Importing Drupal 8 config programmatically
<?php
// Import arbitrary config from a variable.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
// Or, import YAML config an arbitrary directory.
@rvizena
rvizena / stopcarousel.js
Last active May 24, 2022 22:51
Stop Bootstrap carousel from automatically sliding in mobile
$(document).ready(function(){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
$('.carousel-div').attr('data-interval', 'false');
}
});
@rvizena
rvizena / HTML5 Video snippet + Buttons
Last active April 23, 2020 22:26
HTML5 Video - Remove controls, Mute audio (for Chrome), autoplay inline for ios, onplaying for Safari controls, Bootstrap Glyphicons for icons
<video id="myVideo" muted autoplay loop playsinline onplaying="this.controls=false" poster="/images/my-image.jpg" style="pointer-events: none;">
<source src="/path/to/files/video.mp4">
Your browser does not support the video tag.
</video>
<div class="fpButtons">
<button class="btn btn-default btn-sm pause" type="button" >
<span class="glyphicon glyphicon-pause" aria-hidden="true"></span>
</button>
<button class="btn btn-default btn-sm play" type="button" style="display:none;">
<span class="glyphicon glyphicon-play" aria-hidden="true"></span>
@rvizena
rvizena / HTML5 Toggle
Created April 22, 2020 18:52
HTML5 Video Toggle Play/Pause
// HTML5 video element with button toggle
$('button').click(function () {
var mediaVideo = $("#myVideo").get(0);
if (mediaVideo.paused) {
mediaVideo.play();
$('.pause').show();
$('.play').hide();
} else {
$('.play').show();
@rvizena
rvizena / node.twig.html
Created May 10, 2020 07:45 — forked from leahtard/node.twig.html
Get file url in node for Drupal 8 twig template
{# Get URL of single file field #}
{{ node.field_file.entity.uri.value }}
{# Get URL of multi file field #}
{{ node.field_file['#items'].entity.uri.value }}
{# Trun into link #}
{{ file_url(node.field_file.entity.uri.value) }}
{# Check if there is at least one value #}
@rvizena
rvizena / gist:a5b49e3f0a96030bcce76cba89f62b2d
Created April 15, 2021 21:56
Debugging: Find elements wider than the body w/ JS
//place this code into the browser's console
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
@rvizena
rvizena / gist:2f32c28643c162f640916e0a60c25335
Created May 20, 2022 01:06
Drupal 9: require the exact URL from the link reference field
You might be using a link field on your entity type, and if so, you might find yourself in a position where you require the exact URL from the link reference field.
{{ content.field_custom_link.0['#url'] }}
If you need the title, use this instead:
{{ content.field_custom_link.0['#title'] }}
Be sure to switch out the bolded text above for the machine name of your custom link field.
@rvizena
rvizena / gist:05e5f9f097f73f7eb1a0636cdb481e60
Created May 17, 2023 22:46
Twig: How to check if a field value is empty
{% if content.field_myfield is not empty %}
{% endif %}
https://www.drupal.org/forum/support/theme-development/2016-03-18/how-to-check-if-a-field-value-is-empty
@rvizena
rvizena / gist:8c81d17371fee48e280e4e9b9f529487
Created June 1, 2023 19:31
Twig Boolean for show/hide paragraphs
{% if paragraph.field_hide_spotlight.value != 1 %}
<{{ outer_wrapper }}{{ attributes.addClass('ppl-spotlight-wrapper', 'ds-2col-stacked', 'clearfix') }}>
{{ title_suffix.contextual_links }}
<{{ header_wrapper }}{{ header_attributes.addClass('group-header') }}>
{{ header }}
</{{ header_wrapper }}>
<{{ left_wrapper }}{{ left_attributes.addClass('group-left') }}>