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

Commit

Permalink
[SRM-981] Updated module to be compatible with drupal 10. (#48)
Browse files Browse the repository at this point in the history
* [SRM-981] Updated module to be compatible with drupal 10.
  • Loading branch information
MdNadimHossain authored Nov 17, 2023
1 parent 92ab2b4 commit 4dd0bea
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 193 deletions.
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "Search configuration for Tide Drupal 8 distribution",
"description": "Search configuration for Tide Drupal 10 distribution",
"extra": {
"patches": {
"drupal/search_api": {
Expand All @@ -9,6 +9,9 @@
"KeyProviderInterface::getKeyValue() doesn't always return a string - https://www.drupal.org/project/key/issues/3356052#comment-15030602": "https://git.drupalcode.org/project/key/-/merge_requests/11/diffs.patch",
"Deprecated Function: strlen(): Passing null to parameter #1 ($string) - https://www.drupal.org/project/key/issues/3323238": "https://www.drupal.org/files/issues/2023-02-01/3323238-6.patch",
"Error: Call to a member function getKeyValue on null - https://www.drupal.org/project/key/issues/3385523": "https://www.drupal.org/files/issues/2023-09-06/3385523-4.patch"
},
"drupal/data_pipelines": {
"CSV data header row whitespace needs to be cleaned up - https://drupal.org/project/data_pipelines/issues/3391214": "https://www.drupal.org/files/issues/2023-10-03/trim-whitespace-from-csv-header-names-3391214-2.patch"
}
},
"drush": {
Expand All @@ -26,8 +29,8 @@
}
},
"require": {
"dpc-sdp/tide_core": "^3.0.0",
"dpc-sdp/tide_landing_page": "^3.0.0",
"dpc-sdp/tide_core": "^4.0.0",
"dpc-sdp/tide_landing_page": "^4.0.0",
"drupal/elasticsearch_connector": "^7.0",
"drupal/search_api": "^1.11",
"drupal/data_pipelines": "^1.0@alpha",
Expand Down
19 changes: 10 additions & 9 deletions src/TideSearchOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ class TideSearchOperation {
* Remove tide_alert content type from data source if module exists.
*/
public function removeTideAlertFromDatasource() {
if (\Drupal::moduleHandler()->moduleExists('tide_alert')) {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('search_api.index.node');
$node_datasource_settings = $config->get('datasource_settings.entity:node.bundles.selected');
if (!in_array('alert', $node_datasource_settings)) {
$node_datasource_settings[] = 'alert';
$config->set('datasource_settings.entity:node.bundles.selected', $node_datasource_settings);
$config->save();
}
if (!(\Drupal::moduleHandler()->moduleExists('tide_alert'))) {
return;
}
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('search_api.index.node');
$node_datasource_settings = $config->get('datasource_settings.entity:node.bundles.selected');
if (!in_array('alert', $node_datasource_settings)) {
$node_datasource_settings[] = 'alert';
$config->set('datasource_settings.entity:node.bundles.selected', $node_datasource_settings);
$config->save();
}
}

Expand Down
2 changes: 1 addition & 1 deletion tide_search.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Tide Search
description: 'Provides Search and related configuration.'
type: module
package: Tide
core_version_requirement: ^8.9 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- search_api:search_api
- elasticsearch_connector:elasticsearch_connector
Expand Down
180 changes: 0 additions & 180 deletions tide_search.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Install file.
*/

use Drupal\search_api\Item\Field;
use Drupal\tide_search\TideSearchOperation;

/**
Expand All @@ -15,182 +14,3 @@ function tide_search_install() {
$tideSearchOperation = new TideSearchOperation();
$tideSearchOperation->removeTideAlertFromDatasource();
}

/**
* Implements hook_update_dependencies().
*/
function tide_search_update_dependencies() {
$dependencies = [];
$dependencies['tide_search'][8001] = ['tide_core' => 8009];
$dependencies['tide_search'][8005] = ['tide_landing_page' => 8050];
return $dependencies;
}

/**
* Add Path alias field to search index for Topic and Tags.
*/
function tide_search_update_8001() {
$index_storage = \Drupal::entityTypeManager()
->getStorage('search_api_index');
/** @var \Drupal\search_api\IndexInterface $index */
$index = $index_storage->load('node');
if (!$index) {
return;
}

// Index the Topic path.
if (!$index->getField('field_topic_path')) {
$field_topic_path = new Field($index, 'field_topic_path');
$field_topic_path->setType('string');
$field_topic_path->setPropertyPath('field_topic:entity:path');
$field_topic_path->setDatasourceId('entity:node');
$field_topic_path->setLabel('Topic » Taxonomy term » URL alias');
$index->addField($field_topic_path);
}

// Index the Tags path.
if (!$index->getField('field_tags_path')) {
$field_tags_path = new Field($index, 'field_tags_path');
$field_tags_path->setType('string');
$field_tags_path->setPropertyPath('field_tags:entity:path');
$field_tags_path->setDatasourceId('entity:node');
$field_tags_path->setLabel('Tags » Taxonomy term » URL alias');
$index->addField($field_tags_path);
}

$index->save();
}

/**
* Adds field_landing_page_summary field to search api, and updates settings.
*/
function tide_search_update_8002() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('search_api.index.node');
$dependencies = $config->get('dependencies.config');
if (!in_array('field.storage.node.field_landing_page_summary', $dependencies)) {
$dependencies[] = 'field.storage.node.field_landing_page_summary';
$config->set('dependencies.config', $dependencies);
}
$field_settings = $config->get('field_settings');
if (isset($field_settings['field_topic_name']['type']) && $field_settings['field_topic_name']['type'] === 'text') {
$field_settings['field_topic_name']['type'] = 'string';
if (isset($field_settings['field_topic_name']['boost'])) {
unset($field_settings['field_topic_name']['boost']);
}
}
if (isset($field_settings['field_tags_name']['type']) && $field_settings['field_tags_name']['type'] === 'text') {
$field_settings['field_tags_name']['type'] = 'string';
if (isset($field_settings['field_tags_name']['boost'])) {
unset($field_settings['field_tags_name']['boost']);
}
}
if (!isset($field_settings['field_landing_page_summary'])) {
$field_settings['field_landing_page_summary'] = [
'label' => 'Summary',
'datasource_id' => 'entity:node',
'property_path' => 'field_landing_page_summary',
'type' => 'text',
'dependencies' => [
'config' => [
'field.storage.node.field_landing_page_summary',
],
],
];
$config->set('field_settings', $field_settings);
}
$processor_settings = $config->get('processor_settings.html_filter.fields');
if (!in_array('field_landing_page_summary', $processor_settings)) {
$processor_settings[] = 'field_landing_page_summary';
$config->set('processor_settings.html_filter.fields', $processor_settings);
}
$config->save();
}

/**
* Removes alert content type from indexing.
*/
function tide_search_update_8003() {
$tideSearchOperation = new TideSearchOperation();
$tideSearchOperation->removeTideAlertFromDatasource();
}

/**
* Add new content type for Search Listing.
*/
function tide_search_update_8004() {
\Drupal::service('module_installer')->install(['tide_content_collection'], TRUE);
$config_location = [\Drupal::service('extension.list.module')->getPath('tide_search') . '/config/optional'];
$tideSearchOperation = new TideSearchOperation();
$tideSearchOperation->createSearchListingContentType($config_location);
$tideSearchOperation->updateSearchListingFormDisplay($config_location);
$tideSearchOperation->addSearchListingPermissions();
$tideSearchOperation->addSearchListingWorkflows();
$tideSearchOperation->allowJsonApiResources();
$tideSearchOperation->addTaxonomyTerms(
'search_listing_custom_header_com',
['Progress Bar']
);
$tideSearchOperation->addTaxonomyTerms(
'listing_layout_comp_taxonomy',
['TideSearchResultsGrid', 'TideSearchResultsList', 'TideSearchResultsTable']
);
$tideSearchOperation->addTaxonomyTerms(
'listing_results_comp_taxonomy',
['TideSearchResult', 'TideSearchResultCard', 'TideGrantSearchResult']
);
$tideSearchOperation->addSearchableFieldsTerms();
}

/**
* Update search api fields for Ripple 2.0 search.
*/
function tide_search_update_8005() {
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('paragraphs') && $moduleHandler->moduleExists('tide_landing_page')) {
$tideSearchOperation = new TideSearchOperation();
$tideSearchOperation->setCoreSearchApiFields();
}
}

/**
* Install module tide_data_pipeline.
*/
function tide_search_update_8006() {
if (!\Drupal::moduleHandler()->moduleExists('tide_data_pipeline')) {
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['tide_data_pipeline']);
}
}

/**
* Add secondary campaign to search listing.
*/
function tide_search_update_8007() {
\Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers');
$config_location = [\Drupal::service('extension.list.module')->getPath('tide_search') . '/config/optional'];

$config = 'field.field.node.tide_search_listing.field_landing_page_c_secondary';
$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();
}

$form_configs = [
'core.entity_view_display.node.tide_search_listing.default',
'core.entity_form_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();
}
}
6 changes: 6 additions & 0 deletions tide_search.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'add scheduled transitions node tide_search_listing':
title: 'Add scheduled transitions node tide_search_listing'
description: 'Allows user to add scheduled transitions node tide_search_listing.'
'view scheduled transitions node tide_search_listing':
title: 'View scheduled transitions node tide_search_listing'
description: 'Allows user to view scheduled transitions node tide_search_listing.'

0 comments on commit 4dd0bea

Please sign in to comment.