diff --git a/uw_cfg_common.module b/uw_cfg_common.module index 909e8d4f30526d8b5aa2ee407acdf2b3adbfe5aa..289a52133675f7aa445e0727e796a4f1554b78cb 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(). *