Skip to content

Add EntityTrait::getDisplayField() or EntityTrait::getTable() #10843

@kevinquinnyo

Description

@kevinquinnyo

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.4.9

  • Platform and Target: n/a

What you did

Tried to get the displayField directly from an Entity.

What happened

Unable to do so directly from the entity.

What you expected to happen

I think it would be a useful feature to pass down the primaryKey and displayField to the entity. Perhaps the EntityTrait could have a getDisplayField() and getPrimaryKey() ?

Since these methods already exist on the table, maybe it would make more since to allow you to get the full table class directly from an entity? That way I could do something like: echo $entity->getTable()->getDisplayField()

I'm not sure if that would be the better approach or not.

I'm also not sure if that should return the actual property name, or if it should actually internally run $this->get($this->_displayField) and actually return the value.

I think if it just returned the actual displayField name, that might be ok because it would be used something like this:

$displayField = $entity->getDisplayField();
echo $entity->get($displayField); // or simply echo $entity->$displayField;

Maybe there's a better idea for that?

I hope that makes sense. Basically this would be useful if you know you have entities but don't necessarily know which entities (perhaps passed to a template from a global search controller) and you want to display each one's displayField without having to go and ask each one's Table classes.

I'm not sure how hard it would be to implement something like this or really how to go about it. I assume the Marshaler would be responsible for passing it to new Entity classes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions