Skip to content

Instantly share code, notes, and snippets.

View amcgowanca's full-sized avatar

Aaron McGowan amcgowanca

View GitHub Profile
@amcgowanca
amcgowanca / MODULE.module.php
Last active August 29, 2015 14:16
Drupal 7: Restrict available options for View Mode field when creating new for Bean instances
<?php
/**
* @file
*/
/**
* Implements hook_form_FORM_ID_alter().
*
* Retrieves the view mode information for the Bean type and makes available
* as an option only those view modes which apply to this Bean by having
@amcgowanca
amcgowanca / MODULE.module.php
Created February 28, 2015 14:07
Drupal 7: Bean view page override with bean type specific page view callback.
<?php
/**
* Implements hook_menu_alter().
*/
function MODULE_menu_alter(&$items) {
if (isset($items['block/%bean_delta'])) {
$items['block/%bean_delta']['page callback'] = 'MODULE_bean_view_page';
}
}
@amcgowanca
amcgowanca / INFO.md
Created July 1, 2015 03:41
Drupal 7 & Preferred menu links

Drupal 7 and Preferred Menu Links

One would expect that a preferred menu link item would be that link item in a menu which is the default or primary menu link item for any particular path where more than one menu link exists in the same menu with the same link path. For example, when you create a new node instance which allows for menu link creation within the node edit form, it would be expected that when the node is fully loaded (therefore contains the property menu as an array which is loaded via the invocation of hook_node_prepare that is implemented by the menu module) the $node->menu represents the preferred menu link for this node. While we can significantly rely on this method for any node's menu link when retrieved via a node object ($node->menu), we cannot expect to be the same as what may be returned from menu_link_get_preferred('node/' . $node->nid). So which is the the correct preferred menu link?

With the expectation that $node-&gt;menu represents the preferred menu link for th

@amcgowanca
amcgowanca / MYMODULE.module.php
Created December 14, 2015 10:49
Preprocess field and replace HTTP with HTTPs for Sched.org schedules
<?php
/**
* Implements hook_preprocess_field().
*/
function HOOK_preprocess_field(&$variables) {
if ('field_FIELDNAME' == $variables['element']['#field_name'] && isset($GLOBALS['is_https']) && $GLOBALS['is_https']) {
if (!empty($variables['items'])) {
foreach (element_children($variables['items']) as $delta) {
if (!empty($variables['items'][$delta]['#markup'])) {
@amcgowanca
amcgowanca / settings.php
Created September 10, 2017 14:16
Drupal 8: Disable cache entirely...
<?php
$cache_bins = array('bootstrap','config', 'data','default','discovery', 'dynamic_page_cache', 'entity','menu','migrate','render','rest','static','toolbar');
foreach ($cache_bins as $bin) {
$settings['cache']['bins'][$bin] = 'cache.backend.null';
}
@amcgowanca
amcgowanca / ExcludeModule.php
Created November 25, 2017 13:42
Drupal 8: Exclude single modules from always writing to core.extension.yml
<?php
namespace Drupal\module_name\Plugin\ConfigFilter;
use Drupal\config_filter\Plugin\ConfigFilterBase;
/**
* Excludes a set of extensions from exporting to core.extension.yml.
*
* @ConfigFilter(
@amcgowanca
amcgowanca / lightning_workflow-lightning_scheduler-cron-bypass-access.patch
Created April 27, 2018 09:45
Acquia Lightning's Scheduler module needs to bypass access checks during CRON
diff --git a/modules/lightning_scheduler/lightning_scheduler.module b/modules/lightning_scheduler/lightning_scheduler.module
index 94a28a7..61e1532 100644
--- a/modules/lightning_scheduler/lightning_scheduler.module
+++ b/modules/lightning_scheduler/lightning_scheduler.module
@@ -74,6 +74,7 @@ function lightning_scheduler_cron() {
->getStorage($entity_type_id)
->getQuery()
->condition('scheduled_publication', $now, '<=')
+ ->accessCheck(FALSE)
->execute();
@amcgowanca
amcgowanca / jsinjection-prosperworks-gmail.js
Created June 25, 2018 13:00
Helper script for ProsperWorks bugging display behaviour in new Gmail UI
(function (document) {
function updateZIndexValue() {
var elements = document.getElementsByClassName('PWExtensionFrame');
if (elements.length <= 0) {
setTimeout(updateZIndexValue, 500);
console.log('ProsperWorks plugin does not appear initialized yet, waiting...');
return;
}
@amcgowanca
amcgowanca / D7-pathcache-pathinc_reroll.patch
Created July 22, 2018 11:13
Drupal 7.59 reroll of Path Cache modifications
diff --git a/includes/path.inc b/includes/path.inc
index 6bd48d3..d3b8d9f 100644
--- a/includes/path.inc
+++ b/includes/path.inc
@@ -77,8 +77,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) {
$path_language = $path_language ? $path_language : $language_url->language;
if ($action == 'wipe') {
- $cache = array();
- $cache['whitelist'] = drupal_path_alias_whitelist_rebuild();
diff --git a/includes/entity.inc b/includes/entity.inc
index 97c8957..518bc2b 100644
--- a/includes/entity.inc
+++ b/includes/entity.inc
@@ -13,7 +13,7 @@ function d8cache_entity_view($entity, $entity_type, $view_mode, $langcode) {
if ($entity_type == 'node' && $view_mode != 'full') {
// @todo Find a better way to add list cache tags.
- $tags = array_merge($tags, _d8cache_entity_get_list_cache_tags($entity_type));
+ $tags = array_merge($tags, _d8cache_entity_get_list_cache_tags($entity_type, $entity));