Skip to content

Commit

Permalink
Merge pull request #1642 from acquia/ACMS-1972
Browse files Browse the repository at this point in the history
ACMS-1972: Fixing new search index field on field settings and storage page.
  • Loading branch information
vishalkhode1 authored Oct 5, 2023
2 parents f3d42da + db200ae commit d573d0f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
*/
abstract class ContentTypeListTestBase extends ExistingSiteBase {

use AssertLinksTrait;
use SetBackendAvailabilityTrait;
use AssertLinksTrait, SetBackendAvailabilityTrait;

/**
* The machine name of the content type under test.
Expand Down Expand Up @@ -143,7 +142,7 @@ protected function setUp(): void {
'field_' . $this->nodeType . '_type' => $types[2],
'created' => $time++,
]);

\Drupal::getContainer()->get('search_api.post_request_indexing')->destruct();
// Update additional field value.
$this->updateNodeFieldValues();
}
Expand All @@ -162,20 +161,20 @@ abstract protected function getView();
* @param string $langcode
* Langcode to visit tranlated page.
*/
abstract protected function visitListPage($langcode = NULL) : void;
abstract protected function visitListPage($langcode = NULL): void;

/**
* Update specific field value for nodes.
*/
protected function updateNodeFieldValues() : void {}
protected function updateNodeFieldValues(): void {}

/**
* Data provider for testing the listing page with different permissions.
*
* @return array[]
* Sets of arguments to pass to the test method.
*/
public function permissionProvider() : array {
public function permissionProvider(): array {
return [
'anonymous user' => [NULL],
// Search API is really stupid about node access, and does not properly
Expand Down Expand Up @@ -214,7 +213,6 @@ public function testListPage(array $permissions = NULL) {
$module_handler = $this->container->get('module_handler');
if ($module_handler->moduleExists('acquia_cms_search') && $module_handler->moduleExists('acquia_cms_site_studio')) {
$assert_session = $this->assertSession();

// Assert that all categories facets are available.
$assert_session->linkExists('Music (2)');
$assert_session->linkExists('Art (2)');
Expand Down Expand Up @@ -336,7 +334,7 @@ public function testFallback(array $permissions = NULL) {
/**
* {@inheritdoc}
*/
protected function getLinks() : array {
protected function getLinks(): array {
$links = $this->getSession()
->getPage()
->findAll('css', 'article a.card-link');
Expand All @@ -350,7 +348,7 @@ protected function getLinks() : array {
/**
* {@inheritdoc}
*/
protected function getExpectedLinks() : array {
protected function getExpectedLinks(): array {
$ids = $this->getQuery()->accessCheck(FALSE)->execute();

/** @var \Drupal\node\NodeInterface[] $content */
Expand All @@ -371,7 +369,7 @@ protected function getExpectedLinks() : array {
* An entity query object to find all published content of the type under
* test.
*/
protected function getQuery() : QueryInterface {
protected function getQuery(): QueryInterface {
return $this->container->get('entity_type.manager')
->getStorage('node')
->getQuery()
Expand Down
7 changes: 2 additions & 5 deletions modules/acquia_cms_search/acquia_cms_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ function _acquia_cms_search_add_category_facet(array $modules) {
* Implements hook_form_FORM_ID_alter().
*/
function acquia_cms_search_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state) {

/** @var \Drupal\field_ui\Form\FieldConfigEditForm $field_config_form */
$field_config_form = $form_state->getFormObject();

Expand Down Expand Up @@ -224,8 +223,7 @@ function _acquia_cms_search_add_field_to_index_form_builder(string $entity_type,

if ($form_state->getValue('add_to_search_index')) {
$field_storage->setThirdPartySetting('acquia_cms_common', 'search_index', 'content')
->setThirdPartySetting('acquia_cms_common', 'search_label', $fieldConfig->getLabel())
->save();
->setThirdPartySetting('acquia_cms_common', 'search_label', $fieldConfig->getLabel());

// Index entity_reference field.
if ($search_facade->isAllowedTypeReferenceField($field_storage)) {
Expand All @@ -242,7 +240,6 @@ function _acquia_cms_search_add_field_to_index_form_builder(string $entity_type,
// Remove third party setting from fields.storage.config.
$field_storage
->unsetThirdPartySetting('acquia_cms_common', 'search_index')
->unsetThirdPartySetting('acquia_cms_common', 'search_label')
->save();
->unsetThirdPartySetting('acquia_cms_common', 'search_label');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ protected function createSampleContent(string $node_type) {
]);
}
$this->drupalPlaceBlock('facet_block:search_category', ['region' => 'content']);
\Drupal::getContainer()->get('search_api.post_request_indexing')->destruct();
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/src/ExistingSiteJavascript/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected function setUp(): void {
'title' => 'Test unpublished ' . $node_type_label,
'moderation_state' => 'draft',
]);
\Drupal::getContainer()->get('search_api.post_request_indexing')->destruct();
$this->assertFalse($unpublished_node->isPublished());
}
}
Expand Down

0 comments on commit d573d0f

Please sign in to comment.