From dabf6635598db74805a8e0988f48b1ecad281f8a Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Tue, 14 Jan 2025 14:42:53 +0530 Subject: [PATCH] ACMS-4403: Remove unused content type related search view import logic. --- .../acquia_cms_search.install | 1 - .../acquia_cms_search.module | 90 ------------------- 2 files changed, 91 deletions(-) diff --git a/modules/acquia_cms_search/acquia_cms_search.install b/modules/acquia_cms_search/acquia_cms_search.install index 3b1a07bea..f6c0297e6 100644 --- a/modules/acquia_cms_search/acquia_cms_search.install +++ b/modules/acquia_cms_search/acquia_cms_search.install @@ -27,7 +27,6 @@ function acquia_cms_search_install($is_syncing) { $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 = $entity_type_manager->getStorage('facets_facet')->loadByProperties(['id' => 'search_category']); if (!$search_category) { _acquia_cms_search_add_category_facet(); diff --git a/modules/acquia_cms_search/acquia_cms_search.module b/modules/acquia_cms_search/acquia_cms_search.module index 877004cd4..5c1105136 100644 --- a/modules/acquia_cms_search/acquia_cms_search.module +++ b/modules/acquia_cms_search/acquia_cms_search.module @@ -10,14 +10,11 @@ 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\Config\FileStorage; 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\views\Entity\View; -use Drupal\views\ViewEntityInterface; /** * Implements hook_views_data(). @@ -78,7 +75,6 @@ function acquia_cms_search_node_type_insert(NodeTypeInterface $node_type) { if (!$node_type->isSyncing()) { _acquia_cms_search_add_category_facet(); } - _acquia_cms_search_import_content_type_views($node_type); } /** @@ -89,7 +85,6 @@ function acquia_cms_search_node_type_update(NodeTypeInterface $node_type) { if (!$node_type->isSyncing()) { _acquia_cms_search_add_category_facet(); } - _acquia_cms_search_import_content_type_views($node_type); } /** @@ -119,77 +114,6 @@ function acquia_cms_search_field_config_insert(FieldConfigInterface $field_confi if (in_array($field_storage->getType(), $allowed_fields_type)) { Drupal::classResolver(SearchFacade::class)->addFields($field_storage); } - - // Insert view on config import. - $configs = [ - 'node.article.field_article_type' => 'article', - 'node.event.field_event_type' => 'event', - 'node.person.field_person_type' => 'person', - 'node.place.field_place_type' => 'place', - ]; - if (in_array($field_config->id(), array_keys($configs))) { - _acquia_cms_search_import_content_type_views(\Drupal::entityTypeManager()->getStorage('node_type')->load($configs[$field_config->id()])); - } -} - -/** - * Implements hook_ENTITY_TYPE_insert() for node types. - */ -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); - } -} - -/** - * Import views for content types. - */ -function _acquia_cms_search_import_content_type_views(NodeTypeInterface $node_type){ - $content_views = [ - 'article' => 'articles', - 'event' => 'events', - 'person' => 'people', - 'place' => 'places', - ]; - if(!in_array($node_type->id(), array_keys($content_views))) { - return; - } - // Load the view. - $view = View::load($content_views[$node_type->id()]); - if (!$view) { - // import the view. - $source = new FileStorage(__DIR__ . '/config/optional'); - $entity_storage = \Drupal::entityTypeManager()->getStorage('view'); - $view_config = $source->read('views.view.' . $content_views[$node_type->id()]); - // Validate dependencies exist. - if (!empty($view_config['dependencies'])) { - $module_handler = \Drupal::service('module_handler'); - foreach ($view_config['dependencies']['module'] as $dependency) { - if (!$module_handler->moduleExists($dependency)) { - return; - } - } - foreach ($view_config['dependencies']['config'] as $dependency) { - if (!configExists($dependency)) { - return; - } - } - } - - // Create the view entity. - $entity = $entity_storage->createFromStorageRecord($view_config); - $entity->save(); - } } /** @@ -206,20 +130,6 @@ function acquia_cms_search_entity_insert() { } } -/** - * Check if a configuration exists. - * - * @param string $config_name - * The name of the configuration to check. - * - * @return bool - * TRUE if the configuration exists, FALSE otherwise. - */ -function configExists($config_name) { - $config_factory = \Drupal::service('config.factory'); - return $config_factory->get($config_name)->isNew() === FALSE; -} - /** * Implements hook_ENTITY_TYPE_insert() for Search API servers. */