From 99f32e91cc74963adfbd86f1769f479d784c431b Mon Sep 17 00:00:00 2001 From: Deepak Mishra Date: Mon, 23 Dec 2024 10:38:48 +0530 Subject: [PATCH] ACMS-4246: Update acquia_cms_search module for recipe --- .../acquia_cms_search.info.yml | 1 - .../acquia_cms_search.install | 20 ++---- .../acquia_cms_search.module | 27 ++++---- modules/acquia_cms_search/composer.json | 33 ---------- .../install/search_api.index.content.yml | 2 +- .../schema/acquia_cms_search.schema.yml | 62 ++++++++++++++++++- .../src/Facade/SearchFacade.php | 12 ++-- .../AcquiaFacetSearchTest.php | 1 - .../src/Kernel/AcquiaFacetFacadeTest.php | 1 - 9 files changed, 82 insertions(+), 77 deletions(-) diff --git a/modules/acquia_cms_search/acquia_cms_search.info.yml b/modules/acquia_cms_search/acquia_cms_search.info.yml index 74ddb9f01..236651b4f 100644 --- a/modules/acquia_cms_search/acquia_cms_search.info.yml +++ b/modules/acquia_cms_search/acquia_cms_search.info.yml @@ -4,7 +4,6 @@ description: "Provides powerful search capabilities to the site" type: module core_version_requirement: ^10.1 || ^11 dependencies: - - acquia_cms_common:acquia_cms_common - collapsiblock:collapsiblock - facets:facets - facets_pretty_paths:facets_pretty_paths diff --git a/modules/acquia_cms_search/acquia_cms_search.install b/modules/acquia_cms_search/acquia_cms_search.install index 355a01258..1b109bd5d 100644 --- a/modules/acquia_cms_search/acquia_cms_search.install +++ b/modules/acquia_cms_search/acquia_cms_search.install @@ -15,29 +15,17 @@ function acquia_cms_search_install($is_syncing) { // Add permission to the following roles, // so that search autocomplete functionality is accessible. // This will also fix search box design issue if site studio being use. - user_role_grant_permissions('anonymous', [ - 'use search_api_autocomplete for search', - ]); - user_role_grant_permissions('authenticated', [ - 'use search_api_autocomplete for search', - ]); - // Retroactively enable indexing for any content types that existed before // this module was installed. $node_types = NodeType::loadMultiple(); array_walk($node_types, 'acquia_cms_search_node_type_insert'); - $enabled_modules = \Drupal::service('module_handler')->getModuleList(); - $enabled_modules = array_keys($enabled_modules); - _acquia_cms_search_add_category_facet($enabled_modules); + foreach ($node_types as $nodes) { + _acquia_cms_search_add_category_facet($nodes); + } } } -/** - * Implements hook_module_preinstall(). - */ -function acquia_cms_search_module_preinstall($module) { - \Drupal::service('acquia_cms_common.utility')->setModulePreinstallTriggered($module); -} + /** * Added enforced dependency in site studio templates for Acquia CMS Search. diff --git a/modules/acquia_cms_search/acquia_cms_search.module b/modules/acquia_cms_search/acquia_cms_search.module index 06f3a9de6..63f00bd30 100644 --- a/modules/acquia_cms_search/acquia_cms_search.module +++ b/modules/acquia_cms_search/acquia_cms_search.module @@ -12,9 +12,9 @@ use Drupal\acquia_cms_search\Plugin\views\query\SearchApiQuery; use Drupal\acquia_search\Helper\Runtime; use Drupal\Core\DestructableInterface; use Drupal\field\FieldConfigInterface; -use Drupal\node\NodeTypeInterface; use Drupal\search_api\Entity\Index; use Drupal\search_api\ServerInterface; +use Drupal\node\Entity\NodeType; /** * Implements hook_views_data(). @@ -63,7 +63,7 @@ function acquia_cms_search_views_plugins_cache_alter(&$definitions) { /** * Implements hook_ENTITY_TYPE_insert() for node types. */ -function acquia_cms_search_node_type_insert(NodeTypeInterface $node_type) { +function acquia_cms_search_node_type_insert(NodeType $node_type) { Drupal::classResolver(SearchFacade::class)->addNodeType($node_type); } @@ -77,8 +77,8 @@ function acquia_cms_search_field_config_insert(FieldConfigInterface $field_confi // Adding the third party settings in the node.body storage configuration to // index the body field for searching. if ($field_storage->getType() === 'text_with_summary' && $field_storage->id() === 'node.body') { - $field_storage->setThirdPartySetting('acquia_cms_common', 'search_index', 'content') - ->setThirdPartySetting('acquia_cms_common', 'search_label', 'Body') + $field_storage->setThirdPartySetting('acquia_cms_search', 'search_index', 'content') + ->setThirdPartySetting('acquia_cms_search', 'search_label', 'Body') ->save(); } @@ -136,12 +136,12 @@ function acquia_cms_search_search_api_server_insert(ServerInterface $server) { } // If the index wants to opt into using this server, grant its wish. - $server_name = $index->getThirdPartySetting('acquia_cms_common', 'search_server'); + $server_name = $index->getThirdPartySetting('acquia_cms_search', 'search_server'); if ($server_name && $server->id() === $server_name) { $index->setServer($server) ->enable() // The third-party setting is only needed once. - ->unsetThirdPartySetting('acquia_cms_common', 'search_server') + ->unsetThirdPartySetting('acquia_cms_search', 'search_server') ->save(); } } @@ -151,7 +151,7 @@ function acquia_cms_search_search_api_server_insert(ServerInterface $server) { * Implements hook_config_schema_info_alter(). */ function acquia_cms_search_config_schema_info_alter(array &$definitions) { - $key = 'node.type.*.third_party.acquia_cms_common'; + $key = 'node.type.*.third_party.acquia_cms_search'; // Allow node types to carry a 'search_index' setting. This is used by our // facade to passively opt the node type into a particular index. // @see acquia_cms_search_node_type_insert() @@ -183,23 +183,20 @@ function acquia_cms_search_form_acquia_cms_search_form_alter(array &$form) { /** * Implements hook_modules_installed(). */ -function acquia_cms_search_modules_installed(array $modules, $is_syncing) { +function acquia_cms_search_modules_installed(NodeType $nodes, $is_syncing) { if (!$is_syncing) { - _acquia_cms_search_add_category_facet($modules); + _acquia_cms_search_add_category_facet($nodes); } } /** * Adds search_category facet, if any acms search dependent module is installed. * - * @param array $modules + * @param NodeType $nodes * An array of installed modules. */ -function _acquia_cms_search_add_category_facet(array $modules) { - $acquiaCmsSearchModules = ["acquia_cms_person", "acquia_cms_place", - "acquia_cms_article", "acquia_cms_event", "acquia_cms_page", - ]; - if (array_intersect($acquiaCmsSearchModules, $modules)) { +function _acquia_cms_search_add_category_facet(NodeType $nodes) { + if ($nodes) { \Drupal::classResolver(FacetFacade::class)->addFacet([ 'id' => 'search_category', 'name' => 'Category', diff --git a/modules/acquia_cms_search/composer.json b/modules/acquia_cms_search/composer.json index a83874e2e..28448b539 100644 --- a/modules/acquia_cms_search/composer.json +++ b/modules/acquia_cms_search/composer.json @@ -5,44 +5,11 @@ "type": "drupal-module", "require": { "cweagans/composer-patches": "^1.7", - "drupal/acquia_cms_common": "^1.9 || ^2.1 || ^3.1", "drupal/acquia_search": "^3.1", "drupal/collapsiblock": "^4.0", "drupal/facets": "^2.0", "drupal/facets_pretty_paths": "^2.0", "drupal/search_api": "^1.32", "drupal/search_api_autocomplete": "^1.7" - }, - "require-dev": { - "drupal/acquia_cms_tour": "^2" - }, - "repositories": { - "assets": { - "type": "composer", - "url": "https://asset-packagist.org" - }, - "drupal": { - "type": "composer", - "url": "https://packages.drupal.org/8" - } - }, - "config": { - "allow-plugins": { - "composer/installers": true, - "cweagans/composer-patches": true, - "dealerdirect/phpcodesniffer-composer-installer": true, - "drupal/core-composer-scaffold": true, - "ergebnis/composer-normalize": true, - "oomphinc/composer-installers-extender": true, - "phpro/grumphp-shim": true, - "webdriver-binary/binary-chromedriver": true - } - }, - "extra": { - "branch-alias": { - "dev-develop": "1.x-dev" - }, - "enable-patching": true, - "patches": {} } } diff --git a/modules/acquia_cms_search/config/install/search_api.index.content.yml b/modules/acquia_cms_search/config/install/search_api.index.content.yml index ab47530fd..17b7143b0 100644 --- a/modules/acquia_cms_search/config/install/search_api.index.content.yml +++ b/modules/acquia_cms_search/config/install/search_api.index.content.yml @@ -10,7 +10,7 @@ dependencies: module: - acquia_cms_search third_party_settings: - acquia_cms_common: + acquia_starterkit_core: search_server: database id: content name: Content diff --git a/modules/acquia_cms_search/config/schema/acquia_cms_search.schema.yml b/modules/acquia_cms_search/config/schema/acquia_cms_search.schema.yml index 649f43c31..312f2faff 100644 --- a/modules/acquia_cms_search/config/schema/acquia_cms_search.schema.yml +++ b/modules/acquia_cms_search/config/schema/acquia_cms_search.schema.yml @@ -1,8 +1,64 @@ -search_api.index.*.third_party.acquia_cms_common: + +search_api.index.*.third_party.acquia_cms_search: type: mapping - label: 'Acquia CMS settings' + label: 'Acquia Starter Kit Search settings' mapping: - # @see acquia_cms_search_search_api_server_insert() + # @see acquia_cms_search_api_server_insert() search_server: type: string label: 'Machine name of Search API server to which the index will be attached' + +field.storage.*.*.third_party.acquia_cms_search: + type: mapping + label: 'Acquia CMS settings' + mapping: + # Allow fields to carry 'search_index' and 'search_label' settings. This is used + # by our facade to passively opt the field into a particular index. + # @see acquia_cms_search_field_storage_config_insert() + # @see \Drupal\acquia_cms_search\Facade\SearchFacade::addTaxonomyField() + search_index: + type: string + label: 'Machine name of Search API index to which this field should be added' + search_label: + type: string + label: 'The label of the field in the Search API index' + +node.type.*.third_party.acquia_cms_search: + type: mapping + label: 'Acquia Starter Kit settings' + mapping: + # See \Drupal\acquia_cms_common\Facade\WorkflowFacade::addNodeType() + workflow_id: + type: string + label: 'Content Moderation workflow to which this content type should be automatically added' + # See \Drupal\acquia_cms_common\Facade\WorkbenchEmailFacade::addTemplate() + workbench_email_templates: + type: sequence + label: 'E-mail notification templates to which the content type should be automatically added' + sequence: + type: string + label: 'Template ID' + # See \Drupal\acquia_cms_common\Facade\MetatagFacade::addNodeType() + metatag: + type: mapping + label: 'Metatag integration settings' + mapping: + tag_types: + type: sequence + label: 'Tag types to apply to this content type' + sequence: + type: string + label: 'Tag type' + subtype: + type: mapping + label: 'Sub-type information' + mapping: + field: + type: string + label: 'Machine name of the sub-type term reference field for this content type' + facet: + type: string + label: 'Machine name of the sub-type facet on the listing page for this content type' + sitemap_variant: + type: string + label: 'Machine name of the sitemap variant where the content type will be added' diff --git a/modules/acquia_cms_search/src/Facade/SearchFacade.php b/modules/acquia_cms_search/src/Facade/SearchFacade.php index 6e37ab75f..a437ef009 100644 --- a/modules/acquia_cms_search/src/Facade/SearchFacade.php +++ b/modules/acquia_cms_search/src/Facade/SearchFacade.php @@ -7,7 +7,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\field\FieldStorageConfigInterface; -use Drupal\node\NodeTypeInterface; +use Drupal\node\Entity\NodeType; use Drupal\search_api\IndexInterface; use Drupal\search_api\Utility\FieldsHelperInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -100,10 +100,10 @@ public static function create(ContainerInterface $container) { * Tries to add the node type to the list of indexed bundles handled by the * index specified by 'acquia_cms.search_index' third-party setting. * - * @param \Drupal\node\NodeTypeInterface $node_type + * @param \Drupal\node\NodeType $node_type * The new node type. */ - public function addNodeType(NodeTypeInterface $node_type) { + public function addNodeType(NodeType $node_type) { $index = $this->loadIndexFromSettings($node_type); if (empty($index)) { return; @@ -179,7 +179,7 @@ public function addTaxonomyField(FieldStorageConfigInterface $field_storage) { // Field storages don't normally have a human-readable label, so allow it to // provide one in its third-party settings. - $field_label = $field_storage->getThirdPartySetting('acquia_cms_common', 'search_label') ?: $field_storage->getLabel(); + $field_label = $field_storage->getThirdPartySetting('acquia_cms_search', 'search_label') ?: $field_storage->getLabel(); $data_source_id = 'entity:' . $field_storage->getTargetEntityTypeId(); // This will throw an exception if the data source doesn't exist, so this @@ -234,7 +234,7 @@ public function addFields(FieldStorageConfigInterface $field_storage) { $field_type = $field_storage->getType(); // Field storages don't normally have a human-readable label, so allow it to // provide one in its third-party settings. - $field_label = $field_storage->getThirdPartySetting('acquia_cms_common', 'search_label') ?: $field_storage->getLabel(); + $field_label = $field_storage->getThirdPartySetting('acquia_cms_search', 'search_label') ?: $field_storage->getLabel(); $data_source_id = 'entity:' . $field_storage->getTargetEntityTypeId(); // This will throw an exception if the data source doesn't exist, so this @@ -286,7 +286,7 @@ private function loadIndexFromSettings(ThirdPartySettingsInterface $object) : ?I if ($this->configInstaller->isSyncing()) { return NULL; } - $index = $object->getThirdPartySetting('acquia_cms_common', 'search_index'); + $index = $object->getThirdPartySetting('acquia_cms_search', 'search_index'); return $index ? $this->indexStorage->load($index) : NULL; } diff --git a/modules/acquia_cms_search/tests/src/FunctionalJavascript/AcquiaFacetSearchTest.php b/modules/acquia_cms_search/tests/src/FunctionalJavascript/AcquiaFacetSearchTest.php index 1d8e0db0c..0e72bf5b8 100644 --- a/modules/acquia_cms_search/tests/src/FunctionalJavascript/AcquiaFacetSearchTest.php +++ b/modules/acquia_cms_search/tests/src/FunctionalJavascript/AcquiaFacetSearchTest.php @@ -21,7 +21,6 @@ class AcquiaFacetSearchTest extends BrowserTestBase { */ protected static $modules = [ 'block', - 'acquia_cms_common', 'acquia_cms_search', ]; diff --git a/modules/acquia_cms_search/tests/src/Kernel/AcquiaFacetFacadeTest.php b/modules/acquia_cms_search/tests/src/Kernel/AcquiaFacetFacadeTest.php index c70ea63e9..89d4a82a3 100644 --- a/modules/acquia_cms_search/tests/src/Kernel/AcquiaFacetFacadeTest.php +++ b/modules/acquia_cms_search/tests/src/Kernel/AcquiaFacetFacadeTest.php @@ -23,7 +23,6 @@ class AcquiaFacetFacadeTest extends KernelTestBase { 'facets', 'search_api', 'acquia_cms_search', - 'acquia_cms_common', ]; /**