Skip to content

Commit

Permalink
Merge pull request #23862 from eileenmcnaughton/nav
Browse files Browse the repository at this point in the history
Move creating of nav & menu items to legacycustomsearches extension
  • Loading branch information
eileenmcnaughton authored Aug 17, 2022
2 parents eaffe6d + 7d3854d commit 99715d5
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 209 deletions.
7 changes: 0 additions & 7 deletions CRM/Core/xml/Menu/Contact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@
<page_type>1</page_type>
<weight>14</weight>
</item>
<item>
<path>civicrm/contact/search/custom/list</path>
<title>Custom Searches</title>
<page_callback>CRM_Contact_Page_CustomSearch</page_callback>
<page_type>1</page_type>
<weight>16</weight>
</item>
<item>
<path>civicrm/contact/add</path>
<title>New Contact</title>
Expand Down
2 changes: 2 additions & 0 deletions ext/legacycustomsearches/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
</classloader>
<mixins>
<mixin>menu-xml@1.0.0</mixin>
<mixin>mgd-php@1.0.0</mixin>
</mixins>
<civix>
<namespace>CRM/Legacycustomsearches</namespace>
<format>22.05.2</format>
</civix>
</extension>
28 changes: 0 additions & 28 deletions ext/legacycustomsearches/legacycustomsearches.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,3 @@ function legacycustomsearches_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL
function legacycustomsearches_civicrm_entityTypes(&$entityTypes) {
_legacycustomsearches_civix_civicrm_entityTypes($entityTypes);
}

// --- Functions below this ship commented out. Uncomment as required. ---

/**
* Implements hook_civicrm_preProcess().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
*/
//function legacycustomsearches_civicrm_preProcess($formName, &$form) {
//
//}

/**
* Implements hook_civicrm_navigationMenu().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
*/
//function legacycustomsearches_civicrm_navigationMenu(&$menu) {
// _legacycustomsearches_civix_insert_navigation_menu($menu, 'Mailings', array(
// 'label' => E::ts('New subliminal message'),
// 'name' => 'mailing_subliminal_message',
// 'url' => 'civicrm/mailing/subliminal',
// 'permission' => 'access CiviMail',
// 'operator' => 'OR',
// 'separator' => 0,
// ));
// _legacycustomsearches_civix_navigationMenu($menu);
//}
55 changes: 55 additions & 0 deletions ext/legacycustomsearches/managed/Navigation.mgd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use Civi\Api4\Domain;
use CRM_Legacycustomsearches_ExtensionUtil as E;

$menuItems = [];
$domains = Domain::get(FALSE)
->addSelect('id')
->execute();
foreach ($domains as $domain) {
$menuItems[] = [
'name' => 'Custom Searches' . $domain['id'],
'entity' => 'Navigation',
'cleanup' => 'always',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'label' => E::ts('Custom Searches'),
'name' => 'Custom Searches',
'url' => 'civicrm/contact/search/custom/list?reset=1',
'permission' => NULL,
'permission_operator' => 'OR',
'parent_id.name' => 'Search',
'is_active' => TRUE,
'has_separator' => 2,
'weight' => 15,
'domain_id' => $domain['id'],
],
'match' => ['domain_id', 'name'],
],
];
$menuItems[] = [
'name' => 'Manage Custom Searches' . $domain['id'],
'entity' => 'Navigation',
'cleanup' => 'always',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'label' => E::ts('Manage Custom Searches'),
'name' => 'Manage Custom Searches',
'url' => 'civicrm/admin/options/custom_search?reset=1',
'permission' => 'administer CiviCRM',
'permission_operator' => 'OR',
'parent_id.name' => 'Customize Data and Screens',
'is_active' => TRUE,
'weight' => 15,
'domain_id' => $domain['id'],
],
'match' => ['domain_id', 'name'],
],
];
}
return $menuItems;
7 changes: 7 additions & 0 deletions ext/legacycustomsearches/xml/Menu/Search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
<weight>10</weight>
<page_type>1</page_type>
</item>
<item>
<path>civicrm/contact/search/custom/list</path>
<title>Custom Searches</title>
<page_callback>CRM_Contact_Page_CustomSearch</page_callback>
<page_type>1</page_type>
<weight>16</weight>
</item>
</menu>
8 changes: 1 addition & 7 deletions sql/test_data_second_domain.mysql
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ VALUES
( @domainID, 'civicrm/pledge/search&reset=1', 'Find Pledges', 'Find Pledges', 'access CiviPledge', '', @searchlastID, '1', NULL, 10 ),
( @domainID, 'civicrm/activity/search&reset=1', 'Find Activities', 'Find Activities', NULL, '', @searchlastID, '1', '1', 11 );

INSERT INTO civicrm_navigation
( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
VALUES
( @domainID, 'civicrm/contact/search/custom/list&reset=1', 'Custom Searches', 'Custom Searches', NULL, '', @searchlastID, '1', NULL, 12 );

INSERT INTO civicrm_navigation
( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
VALUES
Expand Down Expand Up @@ -287,8 +282,7 @@ VALUES
( @domainID, 'civicrm/admin/setting/preferences/display&reset=1', 'Display Preferences', 'Display Preferences', 'administer CiviCRM', '', @CustomizelastID, '1', NULL, 9 ),
( @domainID, 'civicrm/admin/setting/search&reset=1', 'Search Preferences', 'Search Preferences', 'administer CiviCRM', '', @CustomizelastID, '1', NULL, 10 ),
( @domainID, 'civicrm/admin/menu&reset=1', 'Navigation Menu', 'Navigation Menu', 'administer CiviCRM', '', @CustomizelastID, '1', NULL, 11 ),
( @domainID, 'civicrm/admin/options/wordreplacements&reset=1','Word Replacements','Word Replacements', 'administer CiviCRM', '', @CustomizelastID, '1', NULL, 12 ),
( @domainID, 'civicrm/admin/options/custom_search&reset=1&group=custom_search', 'Manage Custom Searches', 'Manage Custom Searches', 'administer CiviCRM', '', @CustomizelastID, '1', NULL, 13 );
( @domainID, 'civicrm/admin/options/wordreplacements&reset=1','Word Replacements','Word Replacements', 'administer CiviCRM', '', @CustomizelastID, '1', NULL, 12 );

INSERT INTO civicrm_navigation
( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3934,4 +3934,33 @@ protected function addLocationBlockToDomain(): void {
])->execute()->first();
}

/**
* Get an array of tables with rows - useful for diagnosing cleanup issues.
*
* @return array
*/
protected function getTablesWithData(): array {
$dataObject = new CRM_Core_DAO();
$data = [];
$sql = CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT(
'SELECT \"',
table_name,
'\" AS table_name, COUNT(*) AS row_count FROM `',
table_schema,
'`.`',
table_name,
'`' SEPARATOR ' UNION '
)
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = '$dataObject->_database'");
$result = CRM_Core_DAO::executeQuery($sql);
while ($result->fetch()) {
$count = (int) $result->row_count;
if ($count > 0) {
$data[$result->table_name] = $count;
}
}
return $data;
}

}
Loading

0 comments on commit 99715d5

Please sign in to comment.