diff --git a/metsis/metsis_search/config/install/search_api.index.metsis.yml b/metsis/metsis_search/config/install/search_api.index.metsis.yml index 220aab6..f621501 100644 --- a/metsis/metsis_search/config/install/search_api.index.metsis.yml +++ b/metsis/metsis_search/config/install/search_api.index.metsis.yml @@ -52,7 +52,7 @@ third_party_settings: timezone: UTC multilingual: limit_to_content_language: false - include_language_independent: true + include_language_independent: false use_language_undefined_as_fallback_language: false specific_languages: en: '0' @@ -1154,7 +1154,7 @@ datasource_settings: request_handler: '' default_query: '*:*' label_field: title - language_field: ss_language + language_field: '' url_field: related_url_landing_page processor_settings: add_url: { } diff --git a/metsis/metsis_search/config/install/search_api.server.local_metsis.yml b/metsis/metsis_search/config/install/search_api.server.local_metsis.yml index 275e51f..93b3bc3 100644 --- a/metsis/metsis_search/config/install/search_api.server.local_metsis.yml +++ b/metsis/metsis_search/config/install/search_api.server.local_metsis.yml @@ -43,7 +43,7 @@ backend_config: connector: standard connector_config: scheme: http - host: metsis-solr.met.no + host: solr port: 8983 path: / core: testcore diff --git a/metsis/metsis_search/metsis_search.module b/metsis/metsis_search/metsis_search.module index 31025c0..1df1453 100644 --- a/metsis/metsis_search/metsis_search.module +++ b/metsis/metsis_search/metsis_search.module @@ -23,6 +23,7 @@ use Drupal\views\Views; use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Result\Result; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\Yaml\Yaml; /** * Implements hook_help(). @@ -855,6 +856,7 @@ function metsis_search_update_10223() { // Set the new backend plugin ID. $server->set('backend', 'search_api_solr_metsis'); $server->save(); + \Drupal::logger('metsis_update')->notice("Updated search_api_solr backend to 'search_api_solr_metsis'"); } // Update the config // Load the configuration object. @@ -872,25 +874,55 @@ function metsis_search_update_10223() { } /** - * Update function to remove a block if it exists in the block layout. + * Update block configuration. + * + * {@inheritdoc} */ function metsis_search_update_10300() { - // Define the block plugin ID you want to check for and remove. - $block_plugin_id = 'metsis_search_map'; - // Load the configuration factory service. + $block_plugin_id = 'metsis_search_map'; $configFactory = \Drupal::service('config.factory'); - - // Get all the active configurations for block layouts (you may need to adjust this based on your needs). $blockConfigs = $configFactory->listAll('block.block.'); + $views_config_files = ['views.view.metsis_search.yml', + 'views.view.metsis_simple_search.yml', + ]; + $index_config_files = ['search_api.index.metsis_simple_search.yml', + 'search_api.index.metsis_search.yml' + ]; + + $modulePath = \Drupal::service('extension.list.module')->getPath('metsis_search'); + $viewsConfigDir = "$modulePath/config/install"; foreach ($blockConfigs as $configName) { $config = $configFactory->getEditable($configName); if ($config->get('plugin') == $block_plugin_id) { - // If the block is found, remove it by setting its region to 'none'. - \Drupal::logger('metsis_update')->notice("Removed block $block_plugin_id"); + // Remove existing visibility page settings and add '/foo' and '/bar'. + $visibilityPages = ['/metsis/search', '/metsis/simple_search']; + \Drupal::logger('metsis_update')->notice("Disabled block $block_plugin_id and updated visibilty pages"); $config->set('region', 'none'); + // $config->set('visibility.pages', $visibilityPages); $config->save(); + foreach ($views_config_files as $view_config_file) { + // Update the views.view.metsis_search.yml file with the found block configuration ID. + $viewsConfig = \Drupal::service('config.factory')->getEditable($view_config_file); + + if ($viewsConfig !== NULL) { + $dependencies = &$viewsConfig->get('dependencies.config'); + // Add the block configuration to the dependencies of the views config. + if (!in_array($configName, $dependencies)) { + $dependencies[] = $configName; + \Drupal::logger('metsis_update')->notice("Update block config dependencies with $configName"); + } + // Update the entity_block target in the header section with the found block configuration ID. + $headerEntityBlockTarget = &$viewsConfig->get('header.entity_block.target'); + if ($headerEntityBlockTarget !== $configName) { + $headerEntityBlockTarget = str_replace('block.block.', '', $configName); + \Drupal::logger('metsis_update')->notice("Updated block id for header area with: $headerEntityBlockTarget"); + $viewsConfig->set('header.entity_block.target', $headerEntityBlockTarget); + } + $viewsConfig->save(); + } + } } } }