Skip to content

Instantly share code, notes, and snippets.

View a-fro's full-sized avatar

Aaron Froehlich a-fro

  • Cornell University
  • Ithaca, NY
View GitHub Profile
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'submenu_reorder_node_page_reorder') {
foreach (element_children($form['menu_items']) as $id) {
$menu_link = menu_link_load($id);
$url = url($menu_link["link_path"]);
$form['menu_items'][$id]['link_title']['#markup'] = '<a href="'. $url .'">'. $menu_link["link_title"] . '</a>';
}
<?php
namespace Drupal\field_layout\Form;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
# @todo Refactor to use a dynamic RouteSubscriber
field_layout.change_layout:
path: 'admin/structure/types/manage/change-layout/{entity_type}/{bundle}/{display_mode}/{new_layout}'
defaults:
_form: '\Drupal\field_layout\Form\FieldLayoutEntityLayoutEditForm'
_title: 'Change layout'
requirements:
_permission: 'admin fields'
@a-fro
a-fro / reinstall
Created April 12, 2018 21:02
Drupal reinstall script
#!/bin/bash
drush si config_installer config_installer_sync_configure_form.sync_directory=../config/sync --account-pass=admin --account-name="admin" -y
services:
ilr_registrations.default:
class: Drupal\ilr_registrations\EventSubscriber\ClassFilterSubscriber
arguments: []
tags:
- { name: event_subscriber }
<?php
namespace Drupal\ilr_registrations\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
use Drupal\commerce_product\Event\ProductEvents;
use Drupal\commerce_product\Event\FilterVariationsEvent;
/**
@a-fro
a-fro / device-support.css
Created November 15, 2019 16:17
Device support media queries
/* smartphones, touchscreens */
@media (hover: none) and (pointer: coarse) {
/* ... */
}
/* stylus-based screens */
@media (hover: none) and (pointer: fine) {
/* ... */
}
/* Nintendo Wii controller, Microsoft Kinect */
@media (hover: hover) and (pointer: coarse) {
diff --git a/menu_svg_icons.module b/menu_svg_icons.module
index 7ff6e74..601d52f 100644
--- a/menu_svg_icons.module
+++ b/menu_svg_icons.module
@@ -232,6 +232,10 @@ function menu_svg_icons_preprocess_block(&$variables) {
* Implements hook_preprocess_HOOK().
*/
function menu_svg_icons_preprocess_menu(&$variables) {
+ // Make sure there is a menu_name key
+ if (!isset($variables['menu_name'])) {
@a-fro
a-fro / menu_condition_parent_selection_fix.patch
Created January 7, 2020 19:47
Drupal menu_condition patch
diff --git a/src/Plugin/Condition/MenuPosition.php b/src/Plugin/Condition/MenuPosition.php
index 89e640a..099b6c0 100644
--- a/src/Plugin/Condition/MenuPosition.php
+++ b/src/Plugin/Condition/MenuPosition.php
@@ -97,10 +97,9 @@ class MenuPosition extends ConditionPluginBase implements ConditionInterface, Co
*/
public function summary() {
list($menu_name, $link_plugin_id) = explode(':', $this->configuration['menu_parent'], 2);
- $menu_link = $this->pluginManagerMenuLink->createInstance($link_plugin_id);
return $this->t(
diff --git a/src/Controller/ParagraphsPreviewController.php b/src/Controller/ParagraphsPreviewController.php
index 3fe50c4..924c75f 100644
--- a/src/Controller/ParagraphsPreviewController.php
+++ b/src/Controller/ParagraphsPreviewController.php
@@ -176,6 +176,13 @@ class ParagraphsPreviewController extends ControllerBase {
// EntityViewBuilder::viewFieldItem().
$elements = $parent_clone->{$parent_field_name}->view($parent_view_mode);
+ // When layout builder is enabled for an entity, viewBuilder->view_field()
+ // returns and empty array. Using default display options instead returns