Skip to content

Instantly share code, notes, and snippets.

View laradevitt's full-sized avatar

laradevitt laradevitt

  • Othermachines
  • Alberta, Canada
View GitHub Profile
@laradevitt
laradevitt / mytheme.theme
Last active January 31, 2022 19:23
(Drupal 8) A simple back/next pager (based on a views result) for node default display mode.
<?php
use Drupal\views\Views;
// Optional, if using filter values passed via URL (see example below).
use Drupal\Component\Utility\Html;
/**
* Preprocesses variables for node--NODE_TYPE.html.twig.
*
@laradevitt
laradevitt / Code.gs
Created April 17, 2018 20:16
A super simple Google Apps Script app that loads a different version of a Google Form, depending on URL parameter. The alternate version hides a text field and populates its value with the value of the URL parameter.
function doGet(e) {
// The file that will be loaded into the template.
var file = 'index';
// The 'secret' value, optionally passed in via URL.
var secret = '';
// If parameter 'secret' is set, specify an alternate file to load into the
// template and prepare to pass the 'secret' value on.
if (typeof e.parameter.secret != 'undefined' && e.parameter.secret.length) {
@laradevitt
laradevitt / email_domain_users.info
Last active October 25, 2017 20:42
Drupal 7.x: Example module that provides an exported rule that will email users assigned to current domain when content is created. (Domain Access, Rules)
name = Email domain users
description = Example module that provides a rule that will email users assigned to current domain.
core = 7.x
dependencies[] = domain
dependencies[] = domain_views
dependencies[] = entity
dependencies[] = node
dependencies[] = rules
dependencies[] = system
dependencies[] = views
@laradevitt
laradevitt / drupal_entities_to_html.php
Last active September 24, 2017 22:42
(Drupal 8.x) Programmatically load entities by type and build an HTML string consisting of teaser views.
<?php
// Note that I'm building an HTML string for illustrative purposes only since
// best practice is to allow the twig templates to build HTML from the
// structured render arrays.
$html = '';
$storage = \Drupal::entityManager()->getStorage('notice');
$result = \Drupal::entityQuery('notice')
@laradevitt
laradevitt / mytheme.theme
Last active December 4, 2018 20:27
(Drupal 8.x) Load theme CSS into CKEditor for certain formats
<?php
use Drupal\editor\Entity\Editor;
/**
* Implements hook_ckeditor_css_alter().
*
* Original source: https://drupal.stackexchange.com/a/225532
*/
function mytheme_ckeditor_css_alter(array &$css, Editor $editor) {
@laradevitt
laradevitt / mytheme.libraries.yml
Last active September 24, 2017 22:08
(Drupal 8.x) Example code: Add Drupal events to Google calendar with AddToCalendar. https://addtocalendar.com
add-to-calendar:
css:
component:
'//addtocalendar.com/atc/1.5/atc-style-menu-wb.css': {type: external}
js:
'//addtocalendar.com/atc/1.5/atc.min.js': { type: external, minified: true }
@laradevitt
laradevitt / mytheme.theme
Last active September 24, 2017 22:08
(Drupal 8.x) Provide template suggestions for custom block types.
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter().
*
* Original source: @jeff-burnz https://www.drupal.org/node/2724333#comment-11184655
*/
function mytheme_theme_suggestions_block_alter(array &$suggestions, array $vars) {
// Template suggestions for custom block bundles.
@laradevitt
laradevitt / list_drupal_blocks.php
Last active September 24, 2017 22:42
(Drupal 7.x, 8.x) List blocks by region and theme.
<?php
// Drupal 7
$blocks = block_list('sidebar_first');
// Drupal 8 - how nice that you can specify a theme!
$blocks = entity_load_multiple_by_properties('block', array('theme' => $GLOBALS['theme'], 'region' => 'sidebar_first'));
uasort($blocks, 'Drupal\block\Entity\Block::sort');
?>
@laradevitt
laradevitt / exampleTest.js
Created March 4, 2017 18:53
Testing Meteor app with Chimp + Mocha - (1) User login and logout
describe('pages > manageVacancy', function() {
before( function(done) {
// When starting Chimp, passing the --ddp flag provides access to a global
// 'server' object that allows you to call methods via DDP.
// Since the server instance has a separate DDP connection from that between
// browser > server, we need to log in separately first. Requires that your app
@laradevitt
laradevitt / app.js
Created October 13, 2016 18:36
jPlayer + AngularJS + Prismic.io - Simple demo that uses AngularJS and prismic.io API to load an audio file into jPlayer
// Set your API endpoint below!
'use strict';
var app = angular.module('app', ['prismic.io'])
.config(['PrismicProvider', function(PrismicProvider) {
PrismicProvider.setApiEndpoint('https://[YOUR SUBDOMAIN].prismic.io/api');
PrismicProvider.setLinkResolver(function(ctx, doc) {
return 'document/' + doc.id + '/' + doc.slug + ctx.maybeRefParam;