Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
updated hook
Browse files Browse the repository at this point in the history
  • Loading branch information
yeniatencio committed Feb 6, 2024
1 parent e774b21 commit 8a7fce4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/TideSearchOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
56 changes: 29 additions & 27 deletions tide_search.install
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 8a7fce4

Please sign in to comment.