Add link to add a new entity in an empty entity list controller table

Created on 29 September 2012, about 12 years ago
Updated 3 August 2024, 3 months ago

Posted by xjm

This issue is a followup for #1781372: Add an API for listing (configuration) entities and #1783964: Allow entity types to provide menu items .

Problem/Motivation

Proposed resolution

Remaining tasks

User interface changes

Current behavior

Intended behavior

Feature request
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated about 5 hours ago

Created by

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • 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.

  • VDC

    Related to the Views in Drupal Core initiative.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • 🇮🇳India ayush.khare

    Reroll #110 for 10.1.x

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
    1. +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php
      @@ -65,11 +82,17 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
      +    $this->linkGenerator = $link_generator;
      

      Is the disruption of injecting the link generator worth it?

      All the other links we generate in this class (e.g. in operations) don't need/use it so that makes me feel we may not need it.

      That would dramatically reduce the complexity of this patch and the disruption to contrib.

    2. +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php
      @@ -248,4 +269,61 @@ protected function ensureDestination(Url $url) {
      +        Url::fromUri('internal:' . $this->entityType->getLinkTemplate('add-page'))
      ...
      +        Url::fromUri('internal:' . $this->entityType->getLinkTemplate('add-form'))
      

      Is internal: our only option here?

      \Drupal\Core\Entity\Controller\EntityController::addPage uses Link::createFromRoute

    3. +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php
      @@ -248,4 +269,61 @@ protected function ensureDestination(Url $url) {
      +    elseif ($this->entityType->hasLinkTemplate('add-form')) {
      

      This could return an exception if there is no add page link template, but there is an add-form link template but it requires additional parameters. So we probably would need a try/catch here.

      Also, we don't need elseif, there's a return above.

    4. Coming from 🐛 Remove duplicate "add block" link from block content type view's "Results not found" message Postponed I was expecting to see something here for admin lists that are built with views, as in reality most content-entity list builders are overridden with a view. It would be good to get an issue summary update here to address what the intended course of action is there.
Production build 0.71.5 2024