(REF) AfformSaveTrait - Extract helper $isChanged
authorTim Otten <totten@civicrm.org>
Thu, 19 Dec 2019 04:12:54 +0000 (20:12 -0800)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:20 +0000 (19:13 -0700)
I was originally expecting to need to flush the menu whenever the
`permission` changed.  That's not necessary now (because the true permission
check is deferred until it's needed), but the cleanup may still be helpful
in the future (e.g.  if we enable nav-menu integration or change the way
permissions are implemented).

ext/afform/core/Civi/Api4/Utils/AfformSaveTrait.php

index 700146ce951c970fcd8c03650715bffc3eb3c282..eae07c5ee4490115f468aec33be7f469f4c3364e 100644 (file)
@@ -63,7 +63,11 @@ trait AfformSaveTrait {
     // We may have changed list of files covered by the cache.
     _afform_clear();
 
-    if (($item['server_route'] ?? NULL) !== ($orig['server_route'] ?? NULL)) {
+    $isChanged = function($field) use ($item, $orig) {
+      return ($item[$field] ?? NULL) !== ($orig[$field] ?? NULL);
+    };
+    // Right now, permission-checks are completely on-demand.
+    if ($isChanged('server_route') /* || $isChanged('permission') */) {
       \CRM_Core_Menu::store();
       \CRM_Core_BAO_Navigation::resetNavigation();
     }