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

Created on 29 May 2024, about 1 month ago
Updated 28 June 2024, 5 days 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

Needs work

Version

11.0 πŸ”₯

Component
LinkΒ  β†’

Last updated about 24 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
    19 days ago
    Total: 585s
    #198797
  • Status changed to Needs review 19 days 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 13 days 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 days 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.

Production build 0.69.0 2024