EntityLabel Views field Plugin is basically useless - allow to use the EntityLabel field plugin for displaying the entity label of current listing

Created on 3 September 2013, over 11 years ago
Updated 9 January 2025, 27 days ago

The EntityLabel Views Field Plugin should display entity's label and optionally make it into link.

Unfortunately this plugin, even though it's in the core, is useless for common usage.

EntityLabel is right now more like a DynamicEntityReferenceLabel, that requires a field that contains the entity type to load. Most entity types won't have this.

The only place this plugin is implemented right now is file_usage.entity_label, where the file_usage table has an entity type field.

The attached patch adds a helper method to get the entity type and if that's not given, falls back to the entity type definition of the base table. Supporting a third option would be easy to: A static entity type definition, for non-dynamic references.

Does entity_reference.module currently provide something like this?

Patch coming in a minute.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

views.module

Created by

🇨🇭Switzerland berdir Switzerland

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 Kingdom Rory Downes

    I have re-rolled this patch for 10.3.11

  • 🇬🇧United Kingdom joachim

    I think there's a simpler way to do this. Maybe it wasn't available when the patch here was originally made, but every field handler on a view knows which relationship its on, and the result row object has the entity for each relationship.

    This is code from Entity Pager module for doing the same sort of thing:

      protected function getResultEntity(ResultRow $row) {
        return $this->options['relationship']
          ? $row->_relationship_entities[$this->options['relationship']]
          : $row->_entity;
      }
    

    $this->options['relationship'] will need tweaking, as Entity Pager uses its own option definition for that.

  • 🇨🇭Switzerland berdir Switzerland

    This is for the file usage table, which has an type and id column. That's not a relationship and can't be expressed as a relationship because every column can be a different entity type.

Production build 0.71.5 2024