Skip to content

Instantly share code, notes, and snippets.

View ericjgruber's full-sized avatar

Eric J. Gruber ericjgruber

View GitHub Profile
@ericjgruber
ericjgruber / qumu.php
Created January 8, 2020 22:16
Video Embed Field Plugin for Qumu Video
<?php
namespace Drupal\module_name\Plugin\video_embed_field\Provider;
use Drupal\video_embed_field\ProviderPluginBase;
/**
* @VideoEmbedProvider(
* id = "qumu",
* title = @Translation("QUMU")
# These parts extend an existing module's CSS, allowing you to build on top of it.
# THEME.libraries.yml
/**
* In this example, we're extending the eu_cookie_compliance library.
* This part declares the new library you'll be creating to extend the existing
* CSS.
*/
eu_cookie_compliance:
version: 1.x
@ericjgruber
ericjgruber / hook_entity_base_field_info_example
Created December 10, 2019 20:22
Add a field to a Drupal 8 entity.
<?php
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\link\LinkItemInterface;
/**
* Implements hook_entity_base_field_info().
* In this example, you get the id of an existing entity, then add a field to it.
* Here, we create a link field that allows for link text, and then can be
* viewable on the output.
@ericjgruber
ericjgruber / searching_for_forms.module
Created November 1, 2019 20:56
Searching for forms
/**
* Implements hook_form_alter().
*/
function HOOK_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$formIds = [
'eform-submission-guide-request-form' // Example of a $form_id.
];
$formIds = str_replace('-', '_', $formIds); // Change the $form_id to something Drupal understands.
@ericjgruber
ericjgruber / mailer.module
Created April 23, 2019 17:21
Send an email when a Drupal 8 entity has been updated.
<?php
use Drupal\Core\Entity\EntityInterface;
function HOOK_entity_update(EntityInterface $entity) {
$host = 'local';
if (array_key_exists('AH_SITE_ENVIRONMENT', $_ENV)) {
$host = $_ENV['AH_SITE_ENVIRONMENT'];
}
elseif (array_key_exists('AH_SITE_ENVIRONMENT', $_SERVER)) {
@ericjgruber
ericjgruber / trim_url_php
Created January 7, 2019 19:19
Trim url from a Drupal preprocess field
/**
* Implements hook_preprocess_field().
* @param $variables
*/
function THEMENAME_preprocess_field(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node->hasField('field_links_social')) {
$twitter = $node->get('field_links_social')->getValue();
$twitterURL = $twitter[0]["uri"];
@ericjgruber
ericjgruber / gist:cf59158e3be38742c88dbcb0fb56c7ed
Created August 30, 2017 00:15
Restrict kint to four lines to save memory
# settings.local.php
require_once DRUPAL_ROOT . '/modules/contrib/devel/kint/kint/Kint.class.php';
Kint::$maxLevels = 4;
@ericjgruber
ericjgruber / logger.php
Created August 9, 2017 13:45
Drupal 8 "watchdog" logging
try {
// Try something ...
}
catch (\Exception $e) {
// Log the error message
\Drupal::logger('ModuleOrWhateverName')->error($e);
}
$email = \Drupal::currentUser()->getEmail();
var gulp = require('gulp');
var sass = require('gulp-sass');
var shell = require('gulp-shell');
gulp.task('styles', function() {
gulp.src('scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('css/'));
});