Skip to content

Commit

Permalink
ACMS-1972: Fixing new search index field on field settings and storag…
Browse files Browse the repository at this point in the history
…e page
  • Loading branch information
apathak18 committed Sep 29, 2023
1 parent f3d42da commit 1acd6f3
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions modules/acquia_cms_search/acquia_cms_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use Drupal\acquia_cms_search\Facade\FacetFacade;
use Drupal\acquia_cms_search\Facade\SearchFacade;
use Drupal\acquia_cms_search\Plugin\views\query\SearchApiQuery;
use Drupal\acquia_search\Helper\Runtime;
use Drupal\Core\DestructableInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
Expand Down Expand Up @@ -78,6 +79,20 @@ function acquia_cms_search_field_config_insert(FieldConfigInterface $field_confi
}
}

/**
* Implements hook_entity_insert().
*/
function acquia_cms_search_entity_insert() {
// Normally, content is indexed immediately after it is created or modified,
// at the end of the current request. But that means content created
// programmatically (i.e., in the PHPUnit tests) are not being indexed. So,
// explicitly invoke the indexer whenever an entity is created.
$indexer = Drupal::service('search_api.post_request_indexing');
if ($indexer instanceof DestructableInterface) {
$indexer->destruct();
}
}

/**
* Implements hook_ENTITY_TYPE_insert() for Search API servers.
*/
Expand Down Expand Up @@ -175,7 +190,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 +238,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 +255,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');
}
}

0 comments on commit 1acd6f3

Please sign in to comment.