From c7b569d6fe7659a6d223f9b1b4f458de4425cde7 Mon Sep 17 00:00:00 2001 From: Ali Sarfaraz Date: Tue, 2 Mar 2021 10:21:44 +1100 Subject: [PATCH 1/2] Added condition to check if config sync is running before we create fields on new content type. (#81) When a new content type is created its done through updatedb process which will trigger entity_bundle_create. Once it is done we can do a config export which will give us two new fields. If we run the deploy process config import will again try to create the content type and run entity_bundle_create hook which will error out because now the field exists. This will also stop layout changes for the content type form display as it will try to add two new fields to the form layout display. --- tide_site.module | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tide_site.module b/tide_site.module index b7c215e..eb9d4ed 100644 --- a/tide_site.module +++ b/tide_site.module @@ -26,6 +26,11 @@ use Drupal\tide_site\TideSitePathAliasListBuilder; * Implements hook_entity_bundle_create(). */ function tide_site_entity_bundle_create($entity_type_id, $bundle) { + // Don't do anything else during config sync. + if (\Drupal::isConfigSyncing()) { + return; + } + /** @var \Drupal\tide_site\TideSiteFields $fields_helper */ $fields_helper = \Drupal::service('tide_site.fields'); From 48bbd87b9ff52143a74d42b0002b6344cf023fea Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Wed, 24 Mar 2021 17:57:12 +1100 Subject: [PATCH 2/2] [SW-827] Added alter hook for cardLinkEnhancer to handle the url belongs to other sites. (#82) --- tide_site.module | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tide_site.module b/tide_site.module index eb9d4ed..0056e9a 100644 --- a/tide_site.module +++ b/tide_site.module @@ -800,3 +800,49 @@ function tide_site_share_link_token_view_alter(array &$build, EntityInterface $t } } } + +/** + * Implements hook_tide_card_link_enhancer_undo_transform_alter(). + * + * @see Drupal\tide_landing_page\Plugin\jsonapi\FieldEnhancer\CardLinkEnhancer::doUndoTransform() + */ +function tide_site_tide_card_link_enhancer_undo_transform_alter(&$data, &$context) { + if (empty($data['pid']) || empty($data['url'])) { + return; + } + + /** @var \Drupal\tide_site\TideSiteHelper $helper */ + $helper = \Drupal::service('tide_site.helper'); + /** @var \Drupal\tide_site\AliasStorageHelper $alias_helper */ + $alias_helper = \Drupal::service('tide_site.alias_storage_helper'); + + $data['origin_alias'] = $data['alias']; + $data['alias'] = $alias_helper->getPathAliasWithoutSitePrefix($data); + + /** @var \Drupal\path_alias\Entity\PathAlias $path_entity */ + $path_entity = PathAlias::load($data['pid']); + if ($path_entity) { + $node = $alias_helper->getNodeFromPathEntity($path_entity); + if ($node) { + // Get the Site ID parameter. + $request = \Drupal::request(); + $site_id = $request->get('site'); + if (!$site_id) { + return; + } + + // The URL from Tide API is already relative. + $data['origin_url'] = $data['url']; + // Check if the link belongs to the current site. + if ($helper->isEntityBelongToSite($node, $site_id)) { + $site_url = ''; + } + else { + $site_url = $helper->getEntityPrimarySiteBaseUrl($node); + $data['url'] = $helper->getNodeUrlFromPrimarySite($node); + } + // Remove site prefix from the URL. + $data['url'] = $alias_helper->getPathAliasWithoutSitePrefix(['alias' => $data['url']], $site_url); + } + } +}