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

[SW-827] Added alter hook for cardLinkEnhancer to handle the url belongs to other sites. #82

Merged
merged 1 commit into from
Mar 24, 2021

Conversation

MdNadimHossain
Copy link
Contributor

@MdNadimHossain MdNadimHossain commented Mar 22, 2021

Jira

https://digital-engagement.atlassian.net/browse/SW-827

Issue

For the card consolidation story, a new enhancer is added named cardLinkEnhancer. When an internal link is added to the card link field and the added links belong to another site, the FE throws an error on trying to access that link. There is a alter hook for tide_path_enhancer tide_site_tide_path_enhancer_undo_transform_alter that resolves this and the same functionality is need for the cardLinkEnhancer alter hook.

Changes

  1. Added functionality in the cardLinkEnhancer alter hook to handle the link that belongs to other sites.

Related PRs -

dpc-sdp/tide_landing_page#131

Future work

A ticket is created to build a helper function which will be called in both of the alter hook for path enhancer and cardLinkEnhancer as they both are doing the same functionalities. It needs a solution direction and broader test case as the path enhancer is is used widely in all projects.
Ticket - https://digital-engagement.atlassian.net/browse/SDPA-5062
Testing PR- #83

*
* @see Drupal\tide_landing_page\Plugin\jsonapi\FieldEnhancer\CardLinkEnhancer::doUndoTransform()
*/
function tide_site_tide_card_link_enhancer_undo_transform_alter(&$data, &$context) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @MdNadimHossain , I think you have to define your own alter API first, otherwise it wouldn't work, an example can be found here https://github.com/dpc-sdp/tide_core/blob/develop/modules/tide_workflow_notification/tide_workflow_notification.api.php.
correct me if I am wrong @GROwen .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant a tide_site.api.php or you can use drupal/symfony event system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincent-gao
Copy link
Collaborator

vincent-gao commented Mar 24, 2021

@MdNadimHossain , just one question, where did you define hook_tide_card_link_enhancer_undo_transform_alter().?

it says Implements hook_tide_card_link_enhancer_undo_transform_alter(). ,but I cannot find the definition of this hook.
https://github.com/dpc-sdp/tide_site/pull/82/files#diff-1845b0bf3e6a368afb536e79493a96b8973e50352bb4cf725f0a1fb8b42752f9R805

@MdNadimHossain
Copy link
Contributor Author

@MdNadimHossain , just one question, where did you define hook_tide_card_link_enhancer_undo_transform_alter().?

Hey @vincent-gao , here - https://github.com/dpc-sdp/tide_landing_page/blob/80911c88485b21796c80eee6c8dd51016720095e/src/Plugin/jsonapi/FieldEnhancer/CardLinkEnhancer.php#L43
isn't this defines the alter hook for a function - ModuleHandler::alter !

@vincent-gao
Copy link
Collaborator

vincent-gao commented Mar 24, 2021

@MdNadimHossain , just one question, where did you define hook_tide_card_link_enhancer_undo_transform_alter().?

Hey @vincent-gao , here - https://github.com/dpc-sdp/tide_landing_page/blob/80911c88485b21796c80eee6c8dd51016720095e/src/Plugin/jsonapi/FieldEnhancer/CardLinkEnhancer.php#L43
isn't this defines the alter hook for a function - ModuleHandler::alter !

Hi @MdNadimHossain , I think you might want to explicitly define a hook by create a {module_name}.api.php file. so other devs could be easily understand that they can use your API.

@MdNadimHossain
Copy link
Contributor Author

@MdNadimHossain , just one question, where did you define hook_tide_card_link_enhancer_undo_transform_alter().?

Hey @vincent-gao , here - https://github.com/dpc-sdp/tide_landing_page/blob/80911c88485b21796c80eee6c8dd51016720095e/src/Plugin/jsonapi/FieldEnhancer/CardLinkEnhancer.php#L43
isn't this defines the alter hook for a function - ModuleHandler::alter !

Hi @MdNadimHossain , I think you might want to explicitly define a hook by create a {module_name}.api.php file. so other devs could be easily understand that they can use your API.

@vincent-gao good point, I will add it in the tide_landing_page module as this hook belongs to the landing page module.

@MdNadimHossain
Copy link
Contributor Author

@vincent-gao I have added the hook info in tide_landing_page api here - dpc-sdp/tide_landing_page#135

@MdNadimHossain MdNadimHossain merged commit 48bbd87 into develop Mar 24, 2021
@MdNadimHossain MdNadimHossain deleted the SW-827-different-semi-link-handler branch March 24, 2021 06:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants