Skip to content

Commit

Permalink
ACMS-4246: Update acquia_cms_search module for recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakmishra2 committed Dec 23, 2024
1 parent 8cee154 commit 99f32e9
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 77 deletions.
1 change: 0 additions & 1 deletion modules/acquia_cms_search/acquia_cms_search.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 4 additions & 16 deletions modules/acquia_cms_search/acquia_cms_search.install
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 12 additions & 15 deletions modules/acquia_cms_search/acquia_cms_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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()
Expand Down Expand Up @@ -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',
Expand Down
33 changes: 0 additions & 33 deletions modules/acquia_cms_search/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 6 additions & 6 deletions modules/acquia_cms_search/src/Facade/SearchFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class AcquiaFacetSearchTest extends BrowserTestBase {
*/
protected static $modules = [
'block',
'acquia_cms_common',
'acquia_cms_search',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class AcquiaFacetFacadeTest extends KernelTestBase {
'facets',
'search_api',
'acquia_cms_search',
'acquia_cms_common',
];

/**
Expand Down

0 comments on commit 99f32e9

Please sign in to comment.