Skip to content

Commit

Permalink
ACMS-4246: Add helper method to import view on fallback view creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Dec 31, 2024
1 parent 60ee974 commit 825ba7b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
5 changes: 3 additions & 2 deletions modules/acquia_cms_search/acquia_cms_search.install
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ function acquia_cms_search_install($is_syncing) {

// Retroactively enable indexing for any content types that existed before
// this module was installed.
$node_types = \Drupal::entityTypeManager()->getStorage('node_type')->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');
array_walk($node_types, '_acquia_cms_search_import_content_type_views');
$search_category = \Drupal::entityTypeManager()->getStorage('facets_facet')->loadByProperties(['id' => 'search_category']);
$search_category = $entity_type_manager->getStorage('facets_facet')->loadByProperties(['id' => 'search_category']);
if (!$search_category) {
_acquia_cms_search_add_category_facet();
}
Expand Down
38 changes: 29 additions & 9 deletions modules/acquia_cms_search/acquia_cms_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use Drupal\node\NodeTypeInterface;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\ServerInterface;
use Drupal\views\Entity\View;
use Drupal\views\ViewEntityInterface;

/**
* Implements hook_views_data().
Expand Down Expand Up @@ -132,16 +133,21 @@ function acquia_cms_search_field_config_insert(FieldConfigInterface $field_confi
}

/**
* Implements hook_entity_insert().
* Implements hook_ENTITY_TYPE_insert() for node types.
*/
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();
function acquia_cms_search_view_insert(ViewEntityInterface $view) {
$content_views = [
'articles_fallback' => 'article',
'events_fallback' => 'event',
'people_fallback' => 'person',
'places_fallback' => 'place',
];
if(!in_array($view->id(), array_keys($content_views))) {
return;
}
if (!$view->isSyncing()) {
$node_type = \Drupal::entityTypeManager()->getStorage('node_type')->load($content_views[$view->id()]);
_acquia_cms_search_import_content_type_views($node_type);
}
}

Expand Down Expand Up @@ -186,6 +192,20 @@ function _acquia_cms_search_import_content_type_views(NodeTypeInterface $node_ty
}
}

/**
* 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();
}
}

/**
* Check if a configuration exists.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
langcode: en
status: false
status: true
dependencies:
config:
- core.entity_view_mode.node.search_index
Expand Down Expand Up @@ -191,4 +191,3 @@ tracker_settings:
options:
cron_limit: 50
index_directly: true
server: ''

0 comments on commit 825ba7b

Please sign in to comment.