From 5d8acb3f00ac8d9584c511e50b2835dce52f2a8c Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Wed, 6 Jan 2021 11:18:05 -0500 Subject: [PATCH] ISTWCMS-4523: adding cache busting for information for menu when new menu link is added --- uw_cfg_common.module | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/uw_cfg_common.module b/uw_cfg_common.module index 909e8d4f..289a5213 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -9,6 +9,26 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\webform\WebformInterface; use Drupal\webform\WebformSubmissionStorageInterface; +/** + * Implements hook_entity_presave(). + */ +function uw_cfg_common_entity_presave(Drupal\Core\Entity\EntityInterface $entity) { + + // Check if we are on a menu link. + if ($entity->getEntityTypeId() == 'menu_link_content') { + + // Check that we are on a Information For (audience) link. + if ($entity->menu_name->getValue()[0]['value'] == 'uw-menu-audience-menu') { + + // Invalid all the menu caching. + \Drupal::cache('menu')->invalidateAll(); + + // Rebuild all the menus. + \Drupal::service('plugin.manager.menu.link')->rebuild(); + } + } +} + /** * Implements hook_form_FORM_ID_alter(). * -- GitLab