Use a separate method to get path field item alias source path

Created on 21 July 2020, almost 4 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

We have a use case where we want to allow editors to provide an alias to a path related to the entity they are editing. The path field type (\Drupal\path\Plugin\Field\FieldType\PathItem) and associated widget, list and other classes provide useful functionality including validation, path alias generation, but the source for the alias is hard-coded in multiple places to be the canonical entity path. It would be convenient if these classes could be subclassed to leverage the existing functionality and provide aliases for paths other than the canonical route, without having to copy a lot of the existing code into the new subclass just to be able to change the source.

Proposed resolution

  1. Create \Drupal\path\Plugin\Field\FieldType\PathItemInterface that extends \Drupal\Core\Field\FieldItemInterface and defines a getAliasSourcePath() method that returns the (string) alias source path
  2. Update PathItem class to implement the new interface and the new method.
  3. Update code in PathItem, \Drupal\path\Plugin\Field\FieldType\PathFieldItemList, \Drupal\path\Plugin\Field\FieldWidget\PathWidget to use the new method

Remaining tasks

Reviews needed.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

✨ Feature request
Status

Needs work

Version

10.1 ✨

Component
PathΒ  β†’

Last updated 6 days ago

  • Maintained by
  • πŸ‡¬πŸ‡§United Kingdom @catch
Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.69.0 2024