Allow LocalTaskInterface::getTitle() to return a renderable array similar to Link::getText()

Created on 21 January 2022, over 2 years ago
Updated 29 May 2023, over 1 year ago

Problem/Motivation

LocalTaskInterface::getTitle() currently defines a Title as a string. However, local tasks are rendered as Link elements that allow its Title to be a renderable array. A renderable array allows for more elaborate markup to be placed in a local task title.

Proposed resolution

Allow LocalTaskInterface::getTitle() to return a renderable array similar to Link::getText()

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

\Drupal\Core\Menu\LocalTaskInterface::getTitle() now returns a string|array|\Drupal\Component\Render\MarkupInterface similar to \Drupal\Core\Link::getText()

Data model changes

None.

Release notes snippet

LocalTaskInterface::getTitle() now allows to return a renderable array similar to Link::getText()

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
Menu systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡³πŸ‡±Netherlands idebr

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Could we add a simple test coverage for this please

    Thanks.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    FWIW the following methods already return TranslatableMarkup:

    • \Drupal\comment\Plugin\Menu\LocalTask\UnapprovedComments::getTitle
    • \Drupal\config_translation\Plugin\Menu\LocalTask\ConfigTranslationLocalTask::getTitle
    • \Drupal\menu_test\Plugin\Menu\LocalTask\TestTasksSettingsSub1::getTitle

    So I think this really just needs the return type update. We probably don't need to remove the string cast in LocalTaskDefault and I don't think this needs tests.

Production build 0.71.5 2024