Upgrader for menu instead of a managed
authorSamuel Vanhove <samuel@symbiotic.coop>
Thu, 29 Jun 2023 19:32:22 +0000 (15:32 -0400)
committerSamuel Vanhove <samuel@symbiotic.coop>
Thu, 29 Jun 2023 19:32:22 +0000 (15:32 -0400)
ext/civicrm_admin_ui/CRM/CivicrmAdminUi/Upgrader.php [new file with mode: 0644]
ext/civicrm_admin_ui/civicrm_admin_ui.civix.php
ext/civicrm_admin_ui/info.xml
ext/civicrm_admin_ui/managed/SavedSearch_Contact_Search.mgd.php

diff --git a/ext/civicrm_admin_ui/CRM/CivicrmAdminUi/Upgrader.php b/ext/civicrm_admin_ui/CRM/CivicrmAdminUi/Upgrader.php
new file mode 100644 (file)
index 0000000..e055a9a
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+// phpcs:disable
+use CRM_CivicrmAdminUi_ExtensionUtil as E;
+// phpcs:enable
+
+/**
+ * Collection of upgrade steps.
+ */
+class CRM_CivicrmAdminUi_Upgrader extends CRM_Extension_Upgrader_Base {
+
+  protected function replaceFindContactMenuPath($path) {
+    // point Find Contacts menu to the FB/SK version or back to the original path
+    // this is temporary until everything is in FB/SK and we can use the original path
+    $results = \Civi\Api4\Navigation::update(FALSE)
+      ->addValue('url', $path)
+      ->addWhere('name', '=', 'Find Contacts')
+      ->execute();
+  }
+
+  public function install(): void {
+    $this->replaceFindContactMenuPath('civicrm/adminui/contact/search');
+  }
+
+  public function uninstall(): void {
+    $this->replaceFindContactMenuPath('civicrm/contact/search');
+  }
+
+  public function enable(): void {
+    $this->replaceFindContactMenuPath('civicrm/adminui/contact/search');
+  }
+
+  public function disable(): void {
+    $this->replaceFindContactMenuPath('civicrm/contact/search');
+  }
+
+  public function upgrade_1000(): bool {
+    $this->replaceFindContactMenuPath('civicrm/adminui/contact/search');
+    return TRUE;
+  }
+
+}
index 69a952d2b2295480057878ad3947791b95a899f2..ff765700feb006d26ce5d3c7d645f11544c831d2 100644 (file)
@@ -133,8 +133,8 @@ function _civicrm_admin_ui_civix_insert_navigation_menu(&$menu, $path, $item) {
   if (empty($path)) {
     $menu[] = [
       'attributes' => array_merge([
-        'label'      => CRM_Utils_Array::value('name', $item),
-        'active'     => 1,
+        'label' => $item['name'] ?? NULL,
+        'active' => 1,
       ], $item),
     ];
     return TRUE;
index 84dcaee275f8782391fab12706ba96243b174fe4..1b1de89ba6196f26a4f1e5493640660d4a6b87eb 100644 (file)
   <civix>
     <namespace>CRM/CivicrmAdminUi</namespace>
     <angularModule>crmCivicrmAdminUi</angularModule>
-    <format>23.02.0</format>
+    <format>23.02.1</format>
   </civix>
   <mixins>
     <mixin>mgd-php@1.0.0</mixin>
   </mixins>
+  <upgrader>CRM_CivicrmAdminUi_Upgrader</upgrader>
 </extension>
index a297cf824e072f23b1258672098186fa8e295f7f..f6884f933fc873ed3d1f5e9a9541ab0c8ae7da90 100644 (file)
@@ -3,32 +3,6 @@
 use CRM_CivicrmAdminUi_ExtensionUtil as E;
 
 return [
-  // using a temporary alternate path to avoid breaking legacy path
-  [
-    'name' => 'Navigation_Find_Contacts',
-    'entity' => 'Navigation',
-    'cleanup' => 'unused',
-    'update' => 'unmodified',
-    'params' => [
-      'version' => 4,
-      'values' => [
-        'domain_id' => 'current_domain',
-        'label' => E::ts('Find Contacts'),
-        'name' => 'Find Contacts',
-        'url' => 'civicrm/adminui/contact/search',
-        'icon' => NULL,
-        'permission' => NULL,
-        'permission_operator' => '',
-        'parent_id.name' => 'Search',
-        'is_active' => TRUE,
-        'has_separator' => NULL,
-        'weight' => 1,
-      ],
-      'match' => [
-        'name',
-      ],
-    ],
-  ],
   [
     'name' => 'SavedSearch_Find_Contacts',
     'entity' => 'SavedSearch',