Needs work
Project:
Drupal core
Version:
main
Component:
entity system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
2 Jun 2013 at 00:02 UTC
Updated:
18 Mar 2023 at 15:02 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tim.plunkettThis seems to work pretty well.
Comment #3
tim.plunkett#1: status-interface-2009958-1.patch queued for re-testing.
Comment #5
berdirOne problem is that it's called status everywhere but actually has a different meaning for many entity types:
- Node/Comment: published/unpublished
- User: blocked/active
- File: temporary/permament
- Config entities: enabled/disabled
So changing $node->status = NODE_PUBLISHED to $node->enable() actually loses clarity of what we're doing, $node->publish() would make more sense (or something like that). Same for $user->enable()/$user->block().
This is similar to one of the main criticism of TypedData/EntityNG from the Sunday discussion before the DrupalCon, having too generic methods due to too generic interfaces.
A compromise could be, assuming we want to keep the unified ->status, just enforce setStatus() on the interface and leave it up to each entity type interface (or config entities in general) to define meaningful shortcuts?
Comment #6
tim.plunkettmsonnabaum made similar points to me in IRC.
He suggested completely separate interfaces like PublishableInterface and BlockableInterface.
Those could either stand alone, or extend EntityStatusInterface (which would only contain setStatus() as you suggest).
Comment #7
berdirNote: The interface in #1818568: Convert files to the new Entity Field API follows that approach now, I have a getStatus() (which could be removed with an implements this) and specifc methods to check and set to temporary/permanent.
Comment #7.0
berdirUpdated issue summary.
Comment #9
catchThis is the older issue, but #2129953: Abstract entity status out to an interface has more discussion (some of which covers the same ground as here), so closing as duplicate of that.Comment #10
catchI cross-posted with amateescu, moving this back to CNW and 8.3.x, let's do oldest wins after all.
Comment #11
timmillwoodIn #2810381: Add generic status field to ContentEntityBase I am proposing to move the status base field definition to ContentEntityBase, this would then get added to all entity types which define a 'status' entity key. Currently only Node does, but I am looking to add this key to Comment too. Only Node and Comment use status as a published state. This change will allow any other entity types to use status for other needs, but the status entity key will mean published/unpublished.
Comment #12
timmillwoodThis issues looks to specifically focus on config entities, where as what I am looking at in #2810381: Add generic status field to ContentEntityBase is specifically content entities. Therefore I will open a new issue for adding
EntityPublishedInterfacefor content entities, then this issue can stay open to focus on an issue for config entities.I think the config entity interface for the status field should be
EntityEnabledInterface.Comment #13
timmillwood#2811667: Introduce EntityPublishedInterface for content entities is for content entities.
Comment #14
Anonymous (not verified) commentedFor what it's worth, the points made in #6 (3 years ago) are the best approach to take ideally as an API to the end user. The exception to the point is that the base EntityStatusInterface should not contain a
setStatus(int $status);method, as it just exposes magic numbers/constants to the code base, which is the underlying problem that should really be fixed.We need to expose the methods on the domain to completely abstract and invoke the expected changes underneath. For example:
enable()anddisable()- I raised a similar point regarding the interfaces in #2811667: Introduce EntityPublishedInterface for content entities for EntityPublishedInterface, suggestingpublish()andretract(). The other interfaces (ie. BlockableInterface) should expose other methods (block()) to invoke semantic expected changes in the domain. The underlying statuses then become irrelevant and do not need to be exposed to the API at all, there is also then no need to worry about backwards compatibility. At the end of the day the domain will always be the same, and one day the status property might need to be ripped out entirely in favour of something better; the abstraction layer has failed to do it's job if it is not possible to do that.Many interfaces that just allow you to pass in arbitrary values to set on the domain, isn't really an abstraction of anything, and just results in objects that are bags of setters and getters; this leads to anaemic domain design, which just leaves massive scope for error.
Comment #27
andypostIt looks outdated