diff --git a/composer.json b/composer.json index dd70c2e6d..03245b0cd 100644 --- a/composer.json +++ b/composer.json @@ -322,6 +322,9 @@ "drupal/core": "-p2" }, "patches": { + "acquia/cohesion": { + "3340269 - Site Studio Drupal 11.1 compatibility": "https://www.drupal.org/files/issues/2025-01-09/3340269-site-studio-drupal-11-1-compatibility.patch" + }, "drupal/core": { "3328187 - PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in docroot/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 112": "https://git.drupalcode.org/project/drupal/-/merge_requests/3142.patch", "Fix failing test for site studio due to missing file": "https://gist.githubusercontent.com/chandan-singh7929/978c8c3c8b6f1e2de23492e7e562c0c3/raw/f0e7770d94be862e5495ca25662a0a0d5672b785/bypass-library-version-core.patch" diff --git a/composer.lock b/composer.lock index 4a55c2782..674993546 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f7f9e623cf8da30e566ee0d0052fb980", + "content-hash": "a285aa0789cbf1a0b52f8b799237b02c", "packages": [ { "name": "acquia/acquia-cms-starterkit", @@ -83,16 +83,16 @@ }, { "name": "acquia/cohesion", - "version": "8.0.1", + "version": "8.0.2", "source": { "type": "git", "url": "https://github.com/acquia/cohesion.git", - "reference": "9c1fe03d979508e4d606ed3033143f9b345bcce3" + "reference": "edea0bfa3ebc42c519b30d831aaf6fb19107030f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/acquia/cohesion/zipball/9c1fe03d979508e4d606ed3033143f9b345bcce3", - "reference": "9c1fe03d979508e4d606ed3033143f9b345bcce3", + "url": "https://api.github.com/repos/acquia/cohesion/zipball/edea0bfa3ebc42c519b30d831aaf6fb19107030f", + "reference": "edea0bfa3ebc42c519b30d831aaf6fb19107030f", "shasum": "" }, "require": { @@ -140,9 +140,9 @@ ], "description": "Site Studio", "support": { - "source": "https://github.com/acquia/cohesion/tree/8.0.1" + "source": "https://github.com/acquia/cohesion/tree/8.0.2" }, - "time": "2024-10-08T11:09:42+00:00" + "time": "2024-11-20T19:17:26+00:00" }, { "name": "acquia/cohesion-theme", diff --git a/modules/acquia_cms_article/config/optional/field.storage.node.field_article_type.yml b/modules/acquia_cms_article/config/optional/field.storage.node.field_article_type.yml index 75a1e04ec..e29933e78 100644 --- a/modules/acquia_cms_article/config/optional/field.storage.node.field_article_type.yml +++ b/modules/acquia_cms_article/config/optional/field.storage.node.field_article_type.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_article third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Article Type' id: node.field_article_type diff --git a/modules/acquia_cms_article/config/optional/node.type.article.yml b/modules/acquia_cms_article/config/optional/node.type.article.yml index e2b3e26e8..abd82e4a2 100644 --- a/modules/acquia_cms_article/config/optional/node.type.article.yml +++ b/modules/acquia_cms_article/config/optional/node.type.article.yml @@ -5,6 +5,8 @@ dependencies: module: - acquia_cms_article third_party_settings: + acquia_cms_search: + search_index: content acquia_cms_common: workflow_id: editorial workbench_email_templates: @@ -18,7 +20,6 @@ third_party_settings: open_graph: open_graph schema_article: schema_article twitter_cards: twitter_cards - search_index: content subtype: field: field_article_type facet: articles_article_type diff --git a/modules/acquia_cms_article/config/optional/views.view.articles.yml b/modules/acquia_cms_article/config/optional/views.view.articles.yml index 569b6d36b..777fea2d1 100644 --- a/modules/acquia_cms_article/config/optional/views.view.articles.yml +++ b/modules/acquia_cms_article/config/optional/views.view.articles.yml @@ -6,7 +6,6 @@ dependencies: - search_api.index.content - views.view.articles_fallback module: - - acquia_cms_common - acquia_cms_search - search_api - user diff --git a/modules/acquia_cms_common/acquia_cms_common.module b/modules/acquia_cms_common/acquia_cms_common.module index dfb758bb9..a82b753ec 100644 --- a/modules/acquia_cms_common/acquia_cms_common.module +++ b/modules/acquia_cms_common/acquia_cms_common.module @@ -64,23 +64,6 @@ function acquia_cms_common_form_alter(&$form, FormStateInterface $form_state, $f } } -/** - * Implements hook_views_data(). - */ -function acquia_cms_common_views_data() { - return [ - 'views' => [ - 'main_listing_pages_view' => [ - 'title' => t('Main listing pages - Text area'), - 'help' => t('Insert a text area inside a main view listing pages if the search server is available. If the view is not based on a Search API index, this behaves like a standard text area.'), - 'area' => [ - 'id' => 'main_listing_pages_view', - ], - ], - ], - ]; -} - /** * Implements hook_theme(). */ diff --git a/modules/acquia_cms_common/config/optional/field.storage.node.field_categories.yml b/modules/acquia_cms_common/config/optional/field.storage.node.field_categories.yml index f51c716c6..4a88f9cbd 100644 --- a/modules/acquia_cms_common/config/optional/field.storage.node.field_categories.yml +++ b/modules/acquia_cms_common/config/optional/field.storage.node.field_categories.yml @@ -5,7 +5,7 @@ dependencies: - node - taxonomy third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: Categories id: node.field_categories diff --git a/modules/acquia_cms_common/config/schema/acquia_cms_common.schema.yml b/modules/acquia_cms_common/config/schema/acquia_cms_common.schema.yml index a7129c430..79c9eb351 100644 --- a/modules/acquia_cms_common/config/schema/acquia_cms_common.schema.yml +++ b/modules/acquia_cms_common/config/schema/acquia_cms_common.schema.yml @@ -38,7 +38,19 @@ node.type.*.third_party.acquia_cms_common: type: string label: 'Machine name of the sitemap variant where the content type will be added' -field.storage.*.*.third_party.acquia_cms_common: +acquia_cms_common.settings: + type: config_object + label: 'Acquia CMS settings' + mapping: + user_login_redirection: + type: boolean + label: 'Enable special redirection on user login for specific roles' + starter_kit_name: + type: string + label: 'The starterkit name' + +# This is added to make test pass. +field.storage.*.*.third_party.acquia_cms_search: type: mapping label: 'Acquia CMS settings' mapping: @@ -52,14 +64,3 @@ field.storage.*.*.third_party.acquia_cms_common: search_label: type: string label: 'The label of the field in the Search API index' - -acquia_cms_common.settings: - type: config_object - label: 'Acquia CMS settings' - mapping: - user_login_redirection: - type: boolean - label: 'Enable special redirection on user login for specific roles' - starter_kit_name: - type: string - label: 'The starterkit name' diff --git a/modules/acquia_cms_event/config/optional/field.storage.node.field_door_time.yml b/modules/acquia_cms_event/config/optional/field.storage.node.field_door_time.yml index c5b9428fc..c22465ff5 100644 --- a/modules/acquia_cms_event/config/optional/field.storage.node.field_door_time.yml +++ b/modules/acquia_cms_event/config/optional/field.storage.node.field_door_time.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_event third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Door Time' id: node.field_door_time diff --git a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_duration.yml b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_duration.yml index f048fd71e..9b95cdd50 100644 --- a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_duration.yml +++ b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_duration.yml @@ -7,7 +7,7 @@ dependencies: module: - acquia_cms_event third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Event Duration' id: node.field_event_duration diff --git a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_end.yml b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_end.yml index 65f3bc743..31980255f 100644 --- a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_end.yml +++ b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_end.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_event third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Event End Date' id: node.field_event_end diff --git a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_start.yml b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_start.yml index a6a4c2dc9..59a61eae0 100644 --- a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_start.yml +++ b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_start.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_event third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Event Start Date' id: node.field_event_start diff --git a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_type.yml b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_type.yml index 28272988b..5622a5c19 100644 --- a/modules/acquia_cms_event/config/optional/field.storage.node.field_event_type.yml +++ b/modules/acquia_cms_event/config/optional/field.storage.node.field_event_type.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_event third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Event Type' id: node.field_event_type diff --git a/modules/acquia_cms_event/config/optional/node.type.event.yml b/modules/acquia_cms_event/config/optional/node.type.event.yml index 56ee044cd..e4792ca21 100644 --- a/modules/acquia_cms_event/config/optional/node.type.event.yml +++ b/modules/acquia_cms_event/config/optional/node.type.event.yml @@ -5,6 +5,8 @@ dependencies: module: - acquia_cms_event third_party_settings: + acquia_cms_search: + search_index: content acquia_cms_common: workflow_id: editorial workbench_email_templates: @@ -22,7 +24,6 @@ third_party_settings: field: field_event_type facet: events_event_type sitemap_variant: default - search_index: content menu_ui: available_menus: - main diff --git a/modules/acquia_cms_page/config/optional/node.type.page.yml b/modules/acquia_cms_page/config/optional/node.type.page.yml index dfb122148..205c5c614 100644 --- a/modules/acquia_cms_page/config/optional/node.type.page.yml +++ b/modules/acquia_cms_page/config/optional/node.type.page.yml @@ -9,6 +9,8 @@ dependencies: module: - acquia_cms_page third_party_settings: + acquia_cms_search: + search_index: content acquia_cms_common: workflow_id: editorial workbench_email_templates: @@ -23,7 +25,6 @@ third_party_settings: schema_article: schema_article twitter_cards: twitter_cards sitemap_variant: default - search_index: content menu_ui: available_menus: - main diff --git a/modules/acquia_cms_person/config/optional/field.storage.node.field_email.yml b/modules/acquia_cms_person/config/optional/field.storage.node.field_email.yml index 576e90157..96a24fbe2 100644 --- a/modules/acquia_cms_person/config/optional/field.storage.node.field_email.yml +++ b/modules/acquia_cms_person/config/optional/field.storage.node.field_email.yml @@ -7,7 +7,7 @@ dependencies: module: - acquia_cms_person third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: Email id: node.field_email diff --git a/modules/acquia_cms_person/config/optional/field.storage.node.field_job_title.yml b/modules/acquia_cms_person/config/optional/field.storage.node.field_job_title.yml index 9b12d788c..c2add4daa 100644 --- a/modules/acquia_cms_person/config/optional/field.storage.node.field_job_title.yml +++ b/modules/acquia_cms_person/config/optional/field.storage.node.field_job_title.yml @@ -7,7 +7,7 @@ dependencies: module: - acquia_cms_person third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: Job Title id: node.field_job_title diff --git a/modules/acquia_cms_person/config/optional/field.storage.node.field_person_telephone.yml b/modules/acquia_cms_person/config/optional/field.storage.node.field_person_telephone.yml index 6e2ab8b3c..24b6e119c 100644 --- a/modules/acquia_cms_person/config/optional/field.storage.node.field_person_telephone.yml +++ b/modules/acquia_cms_person/config/optional/field.storage.node.field_person_telephone.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_person third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Person Telephone' id: node.field_person_telephone diff --git a/modules/acquia_cms_person/config/optional/field.storage.node.field_person_type.yml b/modules/acquia_cms_person/config/optional/field.storage.node.field_person_type.yml index 03d91426d..f5a3ae5b2 100644 --- a/modules/acquia_cms_person/config/optional/field.storage.node.field_person_type.yml +++ b/modules/acquia_cms_person/config/optional/field.storage.node.field_person_type.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_person third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Person Type' id: node.field_person_type diff --git a/modules/acquia_cms_person/config/optional/node.type.person.yml b/modules/acquia_cms_person/config/optional/node.type.person.yml index 0657a99af..f28eb408e 100644 --- a/modules/acquia_cms_person/config/optional/node.type.person.yml +++ b/modules/acquia_cms_person/config/optional/node.type.person.yml @@ -5,6 +5,8 @@ dependencies: module: - acquia_cms_person third_party_settings: + acquia_cms_search: + search_index: content acquia_cms_common: workflow_id: editorial workbench_email_templates: @@ -22,7 +24,6 @@ third_party_settings: field: field_person_type facet: people_person_type sitemap_variant: default - search_index: content menu_ui: available_menus: - main diff --git a/modules/acquia_cms_place/config/optional/field.storage.node.field_place_address.yml b/modules/acquia_cms_place/config/optional/field.storage.node.field_place_address.yml index 69a2fc3e9..e06e137b2 100644 --- a/modules/acquia_cms_place/config/optional/field.storage.node.field_place_address.yml +++ b/modules/acquia_cms_place/config/optional/field.storage.node.field_place_address.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_place third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Place Address' id: node.field_place_address diff --git a/modules/acquia_cms_place/config/optional/field.storage.node.field_place_telephone.yml b/modules/acquia_cms_place/config/optional/field.storage.node.field_place_telephone.yml index 2c7501052..a25c988ba 100644 --- a/modules/acquia_cms_place/config/optional/field.storage.node.field_place_telephone.yml +++ b/modules/acquia_cms_place/config/optional/field.storage.node.field_place_telephone.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_place third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Place Telephone' id: node.field_place_telephone diff --git a/modules/acquia_cms_place/config/optional/field.storage.node.field_place_type.yml b/modules/acquia_cms_place/config/optional/field.storage.node.field_place_type.yml index 5cb77ad2a..abaf6f54b 100644 --- a/modules/acquia_cms_place/config/optional/field.storage.node.field_place_type.yml +++ b/modules/acquia_cms_place/config/optional/field.storage.node.field_place_type.yml @@ -8,7 +8,7 @@ dependencies: module: - acquia_cms_place third_party_settings: - acquia_cms_common: + acquia_cms_search: search_index: content search_label: 'Place Type' id: node.field_place_type diff --git a/modules/acquia_cms_place/config/optional/node.type.place.yml b/modules/acquia_cms_place/config/optional/node.type.place.yml index ddd8dd153..bc8141cbb 100644 --- a/modules/acquia_cms_place/config/optional/node.type.place.yml +++ b/modules/acquia_cms_place/config/optional/node.type.place.yml @@ -5,6 +5,8 @@ dependencies: module: - acquia_cms_place third_party_settings: + acquia_cms_search: + search_index: content acquia_cms_common: workflow_id: editorial workbench_email_templates: @@ -22,7 +24,6 @@ third_party_settings: field: field_place_type facet: places_place_type sitemap_variant: default - search_index: content menu_ui: available_menus: - main 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..f6c0297e6 100644 --- a/modules/acquia_cms_search/acquia_cms_search.install +++ b/modules/acquia_cms_search/acquia_cms_search.install @@ -24,21 +24,16 @@ function acquia_cms_search_install($is_syncing) { // Retroactively enable indexing for any content types that existed before // this module was installed. - $node_types = NodeType::loadMultiple(); + $entity_type_manager = \Drupal::entityTypeManager(); + $node_types = $entity_type_manager->getStorage('node_type')->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); + $search_category = $entity_type_manager->getStorage('facets_facet')->loadByProperties(['id' => 'search_category']); + if (!$search_category) { + _acquia_cms_search_add_category_facet(); + } } } -/** - * 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..bf056835f 100644 --- a/modules/acquia_cms_search/acquia_cms_search.module +++ b/modules/acquia_cms_search/acquia_cms_search.module @@ -29,6 +29,13 @@ function acquia_cms_search_views_data() { 'id' => 'view_fallback', ], ], + 'main_listing_pages_view' => [ + 'title' => t('Main listing pages - Text area'), + 'help' => t('Insert a text area inside a main view listing pages if the search server is available. If the view is not based on a Search API index, this behaves like a standard text area.'), + 'area' => [ + 'id' => 'main_listing_pages_view', + ], + ], ], ]; } @@ -65,6 +72,19 @@ function acquia_cms_search_views_plugins_cache_alter(&$definitions) { */ function acquia_cms_search_node_type_insert(NodeTypeInterface $node_type) { Drupal::classResolver(SearchFacade::class)->addNodeType($node_type); + if (!$node_type->isSyncing()) { + _acquia_cms_search_add_category_facet(); + } +} + +/** + * Implements hook_ENTITY_TYPE_insert() for node types. + */ +function acquia_cms_search_node_type_update(NodeTypeInterface $node_type) { + Drupal::classResolver(SearchFacade::class)->addNodeType($node_type); + if (!$node_type->isSyncing()) { + _acquia_cms_search_add_category_facet(); + } } /** @@ -76,12 +96,6 @@ 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') - ->save(); - } - if ($field_storage->getType() === 'entity_reference' && $field_storage->getSetting('target_type') === 'taxonomy_term') { Drupal::classResolver(SearchFacade::class)->addTaxonomyField($field_storage); } @@ -136,34 +150,17 @@ 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(); } } } -/** - * Implements hook_config_schema_info_alter(). - */ -function acquia_cms_search_config_schema_info_alter(array &$definitions) { - $key = 'node.type.*.third_party.acquia_cms_common'; - // 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() - // @see \Drupal\acquia_cms_search\Facade\SearchFacade::addNodeType() - if (array_key_exists($key, $definitions)) { - $definitions[$key]['mapping']['search_index'] = [ - 'type' => 'string', - 'label' => 'The machine name of the search index to which this content type should be added', - ]; - } -} - /** * Implements hook_ENTITY_TYPE_update(). */ @@ -181,30 +178,24 @@ function acquia_cms_search_form_acquia_cms_search_form_alter(array &$form) { } /** - * Implements hook_modules_installed(). + * Adds search_category facet, if any acms search dependent module is installed. */ -function acquia_cms_search_modules_installed(array $modules, $is_syncing) { - if (!$is_syncing) { - _acquia_cms_search_add_category_facet($modules); +function _acquia_cms_search_add_category_facet() { + // Check if field_categories field is available. + if (!\Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['field_name' => 'field_categories'])) { + return; } -} -/** - * Adds search_category facet, if any acms search dependent module is installed. - * - * @param array $modules - * 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)) { - \Drupal::classResolver(FacetFacade::class)->addFacet([ - 'id' => 'search_category', - 'name' => 'Category', - 'url_alias' => 'category', - 'field_identifier' => 'field_categories', - ]); + // Check if search_category facet is already created. + if (\Drupal::entityTypeManager()->getStorage('facets_facet')->loadByProperties(['id' => 'search_category'])) { + return; } + + // Create search category facet. + \Drupal::classResolver(FacetFacade::class)->addFacet([ + 'id' => 'search_category', + 'name' => 'Category', + 'url_alias' => 'category', + 'field_identifier' => 'field_categories', + ]); } diff --git a/modules/acquia_cms_search/acquia_cms_search.services.yml b/modules/acquia_cms_search/acquia_cms_search.services.yml new file mode 100644 index 000000000..d5322085c --- /dev/null +++ b/modules/acquia_cms_search/acquia_cms_search.services.yml @@ -0,0 +1,6 @@ +services: + acquia_cms_search.recipe_config_importer: + class: Drupal\acquia_cms_search\EventSubscriber\RecipeConfigImporter + arguments: ['@config.factory', '@config.installer'] + tags: + - { name: event_subscriber } diff --git a/modules/acquia_cms_search/composer.json b/modules/acquia_cms_search/composer.json index a83874e2e..5dcfaf4d5 100644 --- a/modules/acquia_cms_search/composer.json +++ b/modules/acquia_cms_search/composer.json @@ -4,8 +4,6 @@ "license": "GPL-2.0-or-later", "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", 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..5ebcb0c52 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_cms_search: search_server: database id: content name: Content diff --git a/modules/acquia_cms_search/config/optional/views.view.acquia_search.yml b/modules/acquia_cms_search/config/optional/views.view.acquia_search.yml index b892b7c9c..5f44dab07 100644 --- a/modules/acquia_cms_search/config/optional/views.view.acquia_search.yml +++ b/modules/acquia_cms_search/config/optional/views.view.acquia_search.yml @@ -6,10 +6,10 @@ dependencies: - search_api.index.acquia_search_index - system.menu.main module: + - acquia_search - search_api - text - user - - acquia_cms_development id: acquia_search label: 'Acquia Search Solr' module: views 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..a336c8a4c 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,4 +1,4 @@ -search_api.index.*.third_party.acquia_cms_common: +search_api.index.*.third_party.acquia_cms_search: type: mapping label: 'Acquia CMS settings' mapping: @@ -6,3 +6,26 @@ search_api.index.*.third_party.acquia_cms_common: search_server: type: string label: 'Machine name of Search API server to which the index will be attached' + +node.type.*.third_party.acquia_cms_search: + type: mapping + label: 'Search settings' + mapping: + search_index: + type: string + label: 'Machine name of Search API index 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' diff --git a/modules/acquia_cms_search/src/EventSubscriber/RecipeConfigImporter.php b/modules/acquia_cms_search/src/EventSubscriber/RecipeConfigImporter.php new file mode 100644 index 000000000..a3816ec6d --- /dev/null +++ b/modules/acquia_cms_search/src/EventSubscriber/RecipeConfigImporter.php @@ -0,0 +1,161 @@ +configFactory = $config_factory; + $this->configInstaller = $config_installer; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents(): array { + return [ + RecipeAppliedEvent::class => 'onRecipeApply', + ]; + } + + /** + * Import the search related config from related recipe. + * + * @param \Drupal\Core\Recipe\RecipeAppliedEvent $event + * The recipe applied event. + */ + public function onRecipeApply(RecipeAppliedEvent $event): void { + $recipe_name = $this->getRecipeName($event->recipe->path); + if ($recipe_name == 'acquia_starterkit_search') { + $this->configInstaller->installOptionalConfig(NULL, [ + 'module' => 'acquia_cms_search' + ]); + $this->importConfigFromRecipe($event->recipe->path); + $this->importSearchConfig(); + } + elseif ( + str_starts_with($recipe_name, 'acquia_starterkit_') && + in_array($recipe_name, self::CONTENT_MODEL_RECIPES) + ) { + $this->importConfigFromRecipe($event->recipe->path); + } + } + + /** + * Extracts the recipe name from the given path. + * + * @param string $path + * The path to the recipe. + * + * @return string + * The extracted recipe name. + */ + private function getRecipeName(string $path): string { + $exploded = explode('/', $path); + return end($exploded); + } + + /** + * Imports search configuration if it exists. + */ + private function importSearchConfig(): void { + $recipes_applied = $this->configFactory->get('acquia_starterkit_core.settings')->get('recipes_applied') ?? []; + // Filter recipes that are search related. + $recipes = array_intersect($recipes_applied, self::CONTENT_MODEL_RECIPES); + foreach ($recipes as $recipe) { + $recipe_path = $this->getRecipePathByName($recipe); + $this->importConfigFromRecipe($recipe_path . '/' . $recipe); + } + } + + /** + * Imports configuration from the specified recipe path. + * + * @param string $recipe_path + * The path to the recipe. + */ + private function importConfigFromRecipe(string $recipe_path): void { + $search_config_path = $recipe_path . '/search'; + $search_config_path_install = $recipe_path . '/search/install'; + $this->importConfigFromPath($search_config_path_install); + $current_theme = $this->configFactory->get('system.theme')->get('default'); + $search_config_path_current_theme = $search_config_path . '/' . $current_theme; + $this->importConfigFromPath($search_config_path_current_theme); + } + + /** + * Imports configuration from the specified path. + * + * @param string $config_path + * The path to the recipe. + */ + private function importConfigFromPath(string $config_path): void { + $config_source = new FileStorage($config_path); + $this->configInstaller->installOptionalConfig($config_source); + } + + /** + * Gets the path to the recipe by its name. + * + * @param string $recipe_name + * The name of the recipe. + * + * @return string|null + * The path to the recipe, or null if not found. + */ + private function getRecipePathByName(string $recipe_name): ?string { + $finder = new Finder(); + $finder->directories()->in(DRUPAL_ROOT)->name($recipe_name); + + foreach ($finder as $file) { + return $file->getPath(); + } + + return NULL; + } + +} diff --git a/modules/acquia_cms_search/src/Facade/SearchFacade.php b/modules/acquia_cms_search/src/Facade/SearchFacade.php index 6e37ab75f..3ab944227 100644 --- a/modules/acquia_cms_search/src/Facade/SearchFacade.php +++ b/modules/acquia_cms_search/src/Facade/SearchFacade.php @@ -179,8 +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 // is really just a way to prevent the field from using an invalid data @@ -223,9 +222,7 @@ public function addFields(FieldStorageConfigInterface $field_storage) { if (empty($index)) { return; } - $field_name = $field_storage->getName(); - // Bail out if the field already exists on the index. if ($index->getField($field_name)) { return; @@ -234,7 +231,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 +283,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') ?? $object->getThirdPartySetting('acquia_starterkit_core', 'search_index'); return $index ? $this->indexStorage->load($index) : NULL; } diff --git a/modules/acquia_cms_common/src/Plugin/views/area/MainListingPagesView.php b/modules/acquia_cms_search/src/Plugin/views/area/MainListingPagesView.php similarity index 96% rename from modules/acquia_cms_common/src/Plugin/views/area/MainListingPagesView.php rename to modules/acquia_cms_search/src/Plugin/views/area/MainListingPagesView.php index e2c90e665..dd0666190 100644 --- a/modules/acquia_cms_common/src/Plugin/views/area/MainListingPagesView.php +++ b/modules/acquia_cms_search/src/Plugin/views/area/MainListingPagesView.php @@ -1,6 +1,6 @@