Add a generic trait for logic to convert references into Urls in LinkWidget

Created on 29 May 2024, 6 months ago
Updated 14 June 2024, 5 months ago

Problem/Motivation

LinkWidget provides a creative logic for internal links that converts the autocomplete entity value into their equivalent URI and vice-versa along its lifecycle.

That logic is pretty neat and could be interesting to move it to a generic trait in order to be reused by other parts of core or contrib modules that might require this logic.

A good scenario to use this trait and avoid copy&paste code is in https://www.drupal.org/project/drupal/issues/3445993 πŸ“Œ Provide a NavigationLinkBlock Plugin and use Help as an usage example Needs review , where Navigation links might use this logic

Proposed resolution

Move the following methods to a generic trait and implement and use the trait in LinkWidget:

  • LinkWidget::validateUriElement()
  • LinkWidget::getUriAsDisplayableString()
  • LinkWidget::getUserEnteredStringAsUri()

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
LinkΒ  β†’

Last updated about 8 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @plopesc
  • Pipeline finished with Success
    5 months ago
    Total: 585s
    #198797
  • Status changed to Needs review 5 months ago
  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    Initial approach moving the logic to a trait in the core namespace, so it could be used by Link module and others , avoiding to add the dependency on Link module.

    A good candidate to make use of this trait would be πŸ“Œ Provide a NavigationLinkBlock Plugin and use Help as an usage example Needs review once that MR gets in.

    Final trait placement and/or Name is open for discussion, but this initial MR is ready for review.

  • Status changed to RTBC 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Move seems straight forward and non disruptive since function names are same.

    I drafted a simple CR to announce the new trait here https://www.drupal.org/node/3455776 β†’

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    In an ideal world...

    if ($entity_type == 'node' && $entity = \Drupal::entityTypeManager()
            ->getStorage($entity_type)
            ->load($entity_id)) {
            $displayable_string = EntityAutocomplete::getEntityLabels([$entity]);
          }
    

    the validation would some how allow us to use injectable code - a service or something - but it doesn't so this is okay and allows this code to be shared. See how \Drupal\Core\Form\FormValidator::doValidateForm() works.

  • Status changed to Needs work 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Think about this another way - should we introduce another render element - or could we move this to \Drupal\Core\Render\Element\Url and have it as an optional thing?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Looking at how we need to manipulate the value we should add a new form element that accepts a Url object as the value.

  • πŸ‡©πŸ‡ͺGermany luenemann SΓΌdbaden, Germany

    Upgrade issue link.

Production build 0.71.5 2024