Some abstract Typed Data objects (like entities) should be allowed to implement an interface that declares them as "loadable", possibly through a static method on the object itself. This would be especially useful (potentially required) for #1906810: Require type hints for automatic entity upcasting.
/**
* Interface for loadable typed data objects.
*/
interface LoadableInterface {
/**
* Loads a typed data object.
*
* @param array $definition
* The typed data definition.
* @param $id
* The unique identifier of the typed data object to be loaded.
*
* @return \Drupal\Core\TypedData\TypedDataInterface
*
*/
public static function load(array $definition, $id);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | 1983100-29.patch | 11.76 KB | fubhy |
| #24 | 1983100-24.patch | 12.47 KB | fubhy |
| #23 | 1983100-23.patch | 12.58 KB | fubhy |
| #15 | 1983100-15.patch | 11.58 KB | fubhy |
| #14 | 1983100-14.patch | 58.31 KB | fubhy |
Comments
Comment #1
fagoI discussed this already with fubhy and I think it's useful addition. It kind of depends on #1868004: Improve the TypedData API usage of EntityNG to really make sense, but applies to typed integration for all "entity" types anyway.
public static function load($id, $type, $definition) {$type is duplicated here as it has to be part of $definition anyway.
Comment #2
fubhy commentedLoading of lists would not be supported until #1928938: Improve typed data definitions of lists is resolved due to the overloaded 'class' attribute in the typed data definition.
Comment #3
fubhy commentedSomething like this... Needs test coverage though.
Comment #5
fagoShould be $id, $definition so we could make $definition optional for Node::load() and remove node_load()?
Else, this looks good and obviously misses tests + implementation ;-)
Comment #6
fagoComment #7
fubhy commentedComment #9
dawehnerA fix for the views fails.
Comment #11
dawehnerIn general I'm wondering why this patch does not follow the pattern we have for plugins and controllers and will have with entity controller: Have a method which get the container + additional metadata
as most dependencies will be part of the container.
If you have a look at patch you see the need for the container.
Comment #12
fubhy commentedYeah valid point. We can surely forward the container from the plugin manager or something.
Comment #13
Crell commentedWe want to eventually get rid of this class, not use it in more places.
This should return null: http://www.garfieldtech.com/blog/empty-return-values
See above.
Comment #14
fubhy commentedComment #15
fubhy commentedWhoops, accidentally didn't revert the commented out typed data tests.
Comment #17
fubhy commented#15: 1983100-15.patch queued for re-testing.
Comment #19
fubhy commented#15: 1983100-15.patch queued for re-testing.
Comment #20
fubhy commentedbumping to critical as this blocks #1906810: Require type hints for automatic entity upcasting which is also critical.
Comment #21
dawehnerLet's use the fullpath here.
That's odd, shouldn't there be just a single value return if someone couldn't be loaded?
I guess if we depend on the container this should implement ContainerAwareInterface (see the common on top of that one).
We need documentation for the new property.
so i guess it is mxed/
format_string => String::format(). At least sprintf and format_string should not appear in the same class.
What are usecases for that? This seems to be to flexible?
Comment #22
fagohm, it's quite unfortunate that we have to pass on the container.
Can we make it so that definition and container could be optional and you could do Node::load($id) if you care to re-define it?
Comment #23
fubhy commentedRe-roll + Fixing things mentioned in the previous comments.
Comment #24
fubhy commentedWhoops, I screwed up the re-roll.
Comment #25
fagoI must say I dislike that we need to pass on the service container to load() but I see that we need to meet our dependencies somehow. However, what about introducing separate loader objects with proper dependency injection?
In the case of entities we already have them even -> the storage controllers. Could we re-use them somehow, e.g. by having one optional loader class per type which implements a container aware factory in which it gets the right storage controller?
Comment #26
fubhy commentedHmm, that's an interesting idea. How would we pass that information into the data type plugins?
Comment #27
fagoWhich information do we need in the plugins? Wouldn't it be enough to have the loader class in the data type plugin definition?
Comment #28
fubhy commentedI guess, yes.. Some sort of factory reference.
Comment #29
fubhy commentedUploading the LoadableInterface related stuff from #1943846: Improve ParamConverterManager and developer experience for ParamConverters as a separate patch.
Comment #29.0
fubhy commentedUpdating issue summary.
Comment #30
jibran29: 1983100-29.patch queued for re-testing.
Comment #32
berdirI think according to recent discussions with @fubhy, this is no longer required. Please confirm...
Comment #33
fubhy commentedYes, just like the just recently removed IdentifiableInterface we don't want this anymore.