Skip to content

Issue 137 - Allow formatter to set url_only and url_plain. #138

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

Merged
merged 3 commits into from
Feb 24, 2025

Conversation

rosiel
Copy link
Member

@rosiel rosiel commented Feb 7, 2025

GitHub Issue: #137

  • Other Relevant Links (Google Groups discussion, related pull requests,
    Release pull requests, etc.)

What does this Pull Request do?

Puts the "URL only" and "Show URL as plain text" checkboxes on the field formatter settings page for authority links

What's new?

  • The parent, LinkFormatter, "locked down" those fields from inheriting classes by setting their access to true only if you're in a Link Formatter. This PR does the same, setting their access to true if you're in an Authority Link formatter.
  • Does this change require documentation to be updated? No
  • Does this change add any new dependencies? No
  • Does this change require any other modifications to be made to the repository
    (i.e. Regeneration activity, etc.)? No
  • Could this change impact execution of existing code? No

How should this be tested?

A description of what steps someone could take to:

Additional Notes:

Any additional information that you think would be helpful when reviewing this
PR.

Interested parties

Tag (@ mention) interested parties or, if unsure, @Islandora/committers

@seth-shaw-asu seth-shaw-asu self-requested a review February 12, 2025 18:18
Copy link
Member

@seth-shaw-asu seth-shaw-asu left a comment

Choose a reason for hiding this comment

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

As is, this throws an error:

PHP Fatal error: Could not check compatibility between Drupal\\controlled_access_terms\\Plugin\\Field\\FieldFormatter\\AuthorityLinkFormatter::settingsForm(array $form, Drupal\\controlled_access_terms\\Plugin\\Field\\FieldFormatter\\FormStateInterface $form_state) and Drupal\\link\\Plugin\\Field\\FieldFormatter\\LinkFormatter::settingsForm(array $form, Drupal\\Core\\Form\\FormStateInterface $form_state), because class Drupal\\controlled_access_terms\\Plugin\\Field\\FieldFormatter\\FormStateInterface is not available in /var/www/html/drupal/web/modules/contrib/controlled_access_terms/src/Plugin/Field/FieldFormatter/AuthorityLinkFormatter.php on line 35

Add the missing use Drupal\Core\Form\FormStateInterface; statement.

@seth-shaw-asu
Copy link
Member

Okay, so, the form technically saves... but the formatter doesn't actually display the URL when I use the option.

See the form settings:
Screenshot 2025-02-21 113922

The item edit page:
Screenshot 2025-02-21 113941

The view page:
Screenshot 2025-02-21 114008

If we're going to include the options, we should make sure it works.

@seth-shaw-asu
Copy link
Member

Looks like this is an old bug that we didn't realize because we didn't have the option to use it before now.

      if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
        $element[$delta] = [
          '#plain_text' => $link_title,
        ];

should be (untested)

      if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
        $element[$delta] = [
          '#plain_text' =>$url;
        ];

@rosiel
Copy link
Member Author

rosiel commented Feb 22, 2025

oooh, thanks and sorry bout that. Here's the results of testing with the latest commit.

Note: I deliberately put the code to "set link text to the url" AFTER the link text was trimmed. I think that trimming URLs is probably universally a bad plan, but if you argue for edge cases then we can easily move it. Note this only applies when the URL is used as the link text. The plain text URL is never trimmed, ever, and still won't be if we choose to trim the Url-as-link-text.

Standard (no URL only) -> link text configured in field displayed.
Screenshot 2025-02-22 at 7 43 34 AM

With "URL Only" the url is the link text.
Screenshot 2025-02-22 at 7 43 52 AM

With "plain text" it shows as plain text.
Screenshot 2025-02-22 at 7 44 18 AM

With no link text in the field instance, the Source (in this case, FAST) is displayed. Also it gets trimmed if you set the trim too low.
Screenshot 2025-02-22 at 7 45 31 AM

But - my possibly off-kilter contribution - don't trim a URL if it's the link text.

Screenshot 2025-02-22 at 7 46 00 AM

Copy link
Member

@seth-shaw-asu seth-shaw-asu left a comment

Choose a reason for hiding this comment

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

👍

@seth-shaw-asu seth-shaw-asu merged commit 05a0811 into 2.x Feb 24, 2025
10 checks passed
@seth-shaw-asu seth-shaw-asu deleted the #137-url_only-and-url_plain branch February 24, 2025 21:16
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.

2 participants