From 166314bd1bf2ddbf5a343c7a63aa17e488304693 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Sun, 22 Sep 2024 22:42:09 +1000 Subject: [PATCH] Added hook update --- tide_landing_page.install | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tide_landing_page.install b/tide_landing_page.install index b890acf..b3c5a43 100644 --- a/tide_landing_page.install +++ b/tide_landing_page.install @@ -5,6 +5,7 @@ * Tide Landing Page install. */ +use Drupal\Component\Utility\NestedArray; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\paragraphs\Entity\Paragraph; @@ -175,3 +176,42 @@ function tide_landing_page_update_10105() { ]); $field_storage->save(); } + +/** + * Added ability to use reusable paragraphs. + */ +function tide_landing_page_update_10106() { + // Enabled paragraphs_library module. + if (!\Drupal::moduleHandler()->moduleExists('paragraphs_library')) { + /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */ + $module_installer = \Drupal::service('module_installer'); + $module_installer->install(['paragraphs_library']); + } + + \Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers'); + $config_location = [\Drupal::service('extension.list.module')->getPath('tide_landing_page') . '/config/install']; + + $form_configs = [ + 'core.base_field_override.paragraphs_library_item.paragraphs_library_item.paragraphs', + 'field.field.node.landing_page.field_landing_page_component', + ]; + + foreach ($form_configs as $form_config) { + $rewrite = _tide_read_config($form_config, $config_location, FALSE); + $display_config_entity = \Drupal::configFactory()->getEditable($form_config); + $original_config = $display_config_entity->getRawData(); + $rewritten_config = NestedArray::mergeDeep($original_config, $rewrite); + if ($rewritten_config['dependencies']) { + $dependencies = $rewritten_config['dependencies']; + foreach ($dependencies as $type => $items) { + $uniqueItems = array_unique($items); + sort($uniqueItems); + $dependencies[$type] = $uniqueItems; + } + $rewritten_config['dependencies'] = $dependencies; + } + $display_config_entity->setData($rewritten_config); + $display_config_entity->save(); + } +} +