Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SD-563] Added hook to roll out tide_data_driven_component for all cms. #564

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tide_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Installation functions for Tide Core.
*/

use Drupal\field\Entity\FieldConfig;
use Drupal\tide_core\TideCoreOperation;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
Expand Down Expand Up @@ -316,3 +317,44 @@ function tide_core_update_10010() {
$module_installer->install(['tide_tfa']);
}
}

/**
* Enabled tide_data_driven_component module.
*/
function tide_core_update_10011() {
$moduleHandler = \Drupal::service('module_handler');
$moduleInstaller = \Drupal::service('module_installer');
// Enable tide_data_driven_component.
if (!$moduleHandler->moduleExists('tide_data_driven_component')) {
$moduleInstaller->install(['tide_data_driven_component']);
}
if ($moduleHandler->moduleExists('tide_landing_page')) {
// Define the fields to be updated.
$fields_to_update = [
'field_landing_page_component',
'field_landing_page_header',
];
$new_component = 'data_driven_component';

foreach ($fields_to_update as $field_name) {
$field_config = FieldConfig::loadByName('node', 'landing_page', $field_name);

if ($field_config) {
// Get the current handler settings.
$handler_settings = $field_config->getSetting('handler_settings');

// Ensure 'target_bundles' exists in handler settings.
if (isset($handler_settings['target_bundles'])) {
// Add the new component if it does not already exist.
if (!array_key_exists($new_component, $handler_settings['target_bundles'])) {
$handler_settings['target_bundles'][$new_component] = $new_component;

// Update the field configuration with the new handler settings.
$field_config->setSetting('handler_settings', $handler_settings);
$field_config->save();
}
}
}
}
}
}