diff --git a/src/TideSearchOperation.php b/src/TideSearchOperation.php index 2e17eee..3da6514 100644 --- a/src/TideSearchOperation.php +++ b/src/TideSearchOperation.php @@ -76,6 +76,7 @@ public function createSearchListingContentType(array $config_location) { 'field.storage.node.field_listing_results_config' => 'field_storage_config', 'field.storage.node.field_layout_component' => 'field_storage_config', 'field.storage.node.field_results_component' => 'field_storage_config', + 'field.storage.node.field_above_results_content' => 'field_storage_config', 'field.storage.node.field_below_results_content' => 'field_storage_config', 'field.storage.node.field_custom_sort_configuration' => 'field_storage_config', 'field.field.node.tide_search_listing.field_featured_image' => 'field_config', @@ -96,6 +97,7 @@ public function createSearchListingContentType(array $config_location) { 'field.field.node.tide_search_listing.field_listing_results_config' => 'field_config', 'field.field.node.tide_search_listing.field_layout_component' => 'field_config', 'field.field.node.tide_search_listing.field_results_component' => 'field_config', + 'field.field.node.tide_search_listing.field_above_results_content' => 'field_config', 'field.field.node.tide_search_listing.field_below_results_content' => 'field_config', 'field.field.node.tide_search_listing.field_custom_sort_configuration' => 'field_config', 'core.entity_form_display.paragraph.search_listing_header_component.default' => 'entity_form_display', diff --git a/tide_search.install b/tide_search.install index c10f1ca..38c1461 100644 --- a/tide_search.install +++ b/tide_search.install @@ -25,37 +25,39 @@ function tide_search_update_10001() { } } - /** * Adds field_above_results_content field to search api, and updates settings. */ function tide_search_update_10002() { - $config_factory = \Drupal::configFactory(); - $config = $config_factory->getEditable('search_api.index.node'); - $dependencies = $config->get('dependencies.config'); - if (!in_array('field.storage.node.field_above_results_content', $dependencies)) { - $dependencies[] = 'field.storage.node.field_above_results_content'; - $config->set('dependencies.config', $dependencies); - } - $field_settings = $config->get('field_settings'); - if (!isset($field_settings['field_above_results_content'])) { - $field_settings['field_above_results_content'] = [ - 'label' => 'Above results content', - 'datasource_id' => 'entity:node', - 'property_path' => 'field_above_results_content', - 'type' => 'text', - 'dependencies' => [ - 'config' => [ - 'field.storage.node.field_above_results_content', - ], - ], - ]; - $config->set('field_settings', $field_settings); + \Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers'); + $config_location = [\Drupal::service('extension.list.module')->getPath('tide_search') . '/config/optional']; + + $field_configs = [ + 'field.field.node.tide_search_listing.field_above_results_content', + 'field.storage.node.field_above_results_content', + ]; + foreach ($field_configs as $config) { + $type = 'field_config'; + $config_read = _tide_read_config($config, $config_location); + $storage = \Drupal::entityTypeManager()->getStorage($type); + $id = substr($config, strrpos($config, '.') + 1); + if ($storage->load($id) == NULL) { + $config_entity = $storage->createFromStorageRecord($config_read); + $config_entity->save(); + } } - $processor_settings = $config->get('processor_settings.html_filter.fields'); - if (!in_array('field_above_results_content', $processor_settings)) { - $processor_settings[] = 'field_above_results_content'; - $config->set('processor_settings.html_filter.fields', $processor_settings); + + $form_configs = [ + 'core.entity_form_display.node.tide_search_listing.default', + 'core.entity_view_display.node.tide_search_listing.default', + 'core.entity_view_display.node.tide_search_listing.teaser', + ]; + foreach ($form_configs as $form_config) { + $config = \Drupal::configFactory()->getEditable($form_config); + $config_read = _tide_read_config($form_config, $config_location, FALSE); + $config->set('dependencies', $config_read['dependencies']); + $config->set('content', $config_read['content']); + $config->set('hidden', $config_read['hidden']); + $config->save(); } - $config->save(); }