Skip to content

Instantly share code, notes, and snippets.

@johncionci
johncionci / lazyresponsive.php
Last active October 25, 2019 13:24
Drupal 8 Responsive Image Preprocess
// Adding a lazyloading option to all responsive images
// Need to figure out the array for each 'srcset'
function bcbs_preprocess_responsive_image(&$variables) {
// kint($variables['sources'][0]['srcset']);
// kint($variables['sources'][0]);
$variables['sources'][0]['data-src'] = $variables['sources'][0]['srcset'];
// $variables['sources'][0]['srcset'] == $variables['sources'][0]['data-srcset'];
// unset($variables['sources'][0]['srcset']);
@johncionci
johncionci / errors.txt
Created April 23, 2019 16:26
Drupal Errors & Fixes
Getting this error during config import:
`Unable to uninstall the <em class="placeholder">Minimal</em> profile since it is the install profile.`
Try this: https://www.drupal.org/project/drupal/issues/2870028#comment-12042807
Set {profile name} equal to {module name}
@johncionci
johncionci / variables.twig
Last active May 21, 2019 14:22
Drupal 8 Template Variables
# ensure that cache tags bubble up as expected.
# this avoids the use of {{ content|without() }}
{% set catch_cache=content|render %}
# checking for values in templates
# gettig value from muti-value field in node template
{% if node.field_related_topics is not empty %}
<h2>{{ 'Related Topics'|t }}</h2>
{{ content.field_related_topics }}
{% endif %}
+function($){
var posts = $('.row-actions .edit a').map(function(){ return $(this).attr('href'); }).get();
var save = function() {
var url, win, timer;
if (!(url = posts.pop())) {
return;
}
win = open(url);
win.onload = function() {
@johncionci
johncionci / add-textdomain.php
Created May 10, 2016 13:40 — forked from balbuf/add-textdomain.php
Add or update text domain of all WP i18n functions in a file
<?php
/**
* Console application, which adds textdomain argument
* to all i18n function calls
*
* Adapted from:
* http://develop.svn.wordpress.org/trunk/tools/i18n/add-textdomain.php
*
* Extended such that all text domains are replaced if found or added otherwise.
* Also, double-quoted strings are replaced by single-quoted strings.
@johncionci
johncionci / mobile-nav.js
Created April 12, 2016 20:01
Insert Submenu Toggle Items
// insert a toggle icon for subnav elements when on mobile
$('<span class="sub-toggle-icon"><i class="fa fa-angle-down"></i><i class="fa fa-angle-up"></i></span>').insertAfter('.main-navigation .menu > li.menu-item-has-children > a');
$('.sub-toggle-icon').bind('click', function(e){
$(this).parent().find('.sub-menu').slideToggle('fast');
$(this).parent().toggleClass('expanded');
e.preventDefault();
});
@johncionci
johncionci / wp-wysiwyg.php
Last active December 2, 2015 17:46
Remove WYSIWYG Options
/**
* Remove certain options from the WYSIWYG editor
* @param [type] $arr Element descriptions that are allowed in the editor
* @return [type] array The array of allowable tags for the editor
*/
function _remove_blockformats( $arr ) {
$arr['block_formats'] = "Paragraph=p; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6; Preformatted=pre";
return $arr;
}
add_filter( 'tiny_mce_before_init', '_remove_blockformats' );
@johncionci
johncionci / rt.scss
Created October 23, 2015 18:04
Sass Responsive Typography Mixin
// rt = Responsive Typography
// @params = Each of the params are synced up with the breakpoints that are defined in the _config.scss file. Feel free to add/remove on per project basis.
@mixin rt($default:null, $sm:null, $md:null, $lg:null, $xl:null) {
@if $default == null {
@error "You must provide at least one value.";
} @else {
font-size: $default;
}
@if $sm != null and $sm != '' {
@johncionci
johncionci / gist:b0d76da299bbbfd11385
Last active August 29, 2015 14:20
Double Off-Canvas Drawers
/**
* Slide in Search & Menu
* Original concept http://codepen.io/svinkle/pen/vCfoK
* @johncionci
*/
$(function() {
var $page = $('#page');
var $closeSearch = $('.close-toggle-search');
var $closeMenu = $('.close-toggle-menu');
// since we have two menus we break into multiple functions
@johncionci
johncionci / theme_customizer.php
Last active August 29, 2015 14:14
WordPress Theme Customizer | Include plugin style theme options
<?php
/**
* Theme Plugin Customizer uses the Core customizer screen to enable or disable
* theme specific plugins. We first add the plugins to the $theme_plugins array()
* from there we can conditionally include required files to enhance theme capabilities.
*/
class Theme_Plugin_Customizer {
/**
* This hooks into 'customize_register' (available as of WP 3.4) and allows