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

Closes #3821: Make the # link stays at the current page #3933

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

BaoNguyen09
Copy link
Contributor

Description

Fix: Make the # link stays at the current page

Related issues

Closes #3821

How to test

  1. Add a card to a page
  2. Add # to the link URL field
  3. Save
  4. Observe the link redirecting the user to the current page

Types of changes

Arizona Quickstart (install profile, custom modules, custom theme)

  • Patch release changes
    • Bug fix
    • Accessibility, performance, or security improvement
    • Critical institutional link or brand change
    • Adding experimental module
    • Update experimental module
  • Minor release changes
    • New feature
    • Breaking or visual change to existing behavior
    • Upgrade experimental module to stable
    • Enable existing module by default or database update
    • Non-critical brand change
    • New internal API or API improvement with backwards compatibility
    • Risky or disruptive cleanup to comply with coding standards
    • High-risk or disruptive change (requires upgrade path, risks regression, etc.)
  • Other or unknown
    • Other or unknown

Drupal core

  • Patch release changes
    • Security update
    • Patch level release (non-security bug-fix release)
    • Patch removal that's no longer necessary
  • Minor release changes
    • Major or minor level update
  • Other or unknown
    • Other or unknown

Drupal contrib projects

  • Patch release changes
    • Security update
    • Patch or minor level update
    • Add new module
    • Patch removal that's no longer necessary
  • Minor release changes
    • Major level update
  • Other or unknown
    • Other or unknown

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My change requires release notes.

@BaoNguyen09 BaoNguyen09 requested a review from a team as a code owner December 9, 2024 23:32
…mepage-instead-of-the-same-page' into 3821-the-link-now-goes-to-the-homepage-instead-of-the-same-page
@bberndt-uaz
Copy link
Contributor

bberndt-uaz commented Dec 11, 2024

This works! 👍 From a quick test in Probo, entering #heading in the Card Link URL field results in a link that looks like this:

<a href="/brian-test-page#heading" class="btn-block">Card link to heading</a>

As an alternative, we could consider skipping the addition of the path and we could just use the anchor exactly as entered by the user. In that case, we could set $link_url to something like Url::fromUri(urldecode('internal:' . $item->link_uri)). Then the resulting href for the link would include only the anchor tag, matching how it currently works when creating an anchor link in a text paragraph:

<a href="#heading" class="btn-block">Card link to heading</a>

Copy link
Contributor

@joshuasosa joshuasosa left a comment

Choose a reason for hiding this comment

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

Good improvement that works. Could look into the suggested alternative. I also see that the Link field formatter works fine with these kinds of links. Could investigate how the field formatter works (e.g., the 'Where' field on Event type works properly).

@BaoNguyen09
Copy link
Contributor Author

Good improvement that works. Could look into the suggested alternative. I also see that the Link field formatter works fine with these kinds of links. Could investigate how the field formatter works (e.g., the 'Where' field on Event type works properly).

Can you provide me where the code for it lies, I've looked through the az_event module but I didn't find the code for this

@joshuasosa
Copy link
Contributor

Good improvement that works. Could look into the suggested alternative. I also see that the Link field formatter works fine with these kinds of links. Could investigate how the field formatter works (e.g., the 'Where' field on Event type works properly).

Can you provide me where the code for it lies, I've looked through the az_event module but I didn't find the code for this

The 'Where' field uses Link which is part of Drupal core. I don't know where the code is exactly but finding it and seeing what they do would be the investigate part. Otherwise, this PR seems to work well enough.

@BaoNguyen09
Copy link
Contributor Author

Then I'm fine with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using # in card link field now goes to the homepage instead of the same page
3 participants