Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Jul 2013 at 11:59 UTC
Updated:
12 Nov 2014 at 09:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tim.plunkettAs of #2035315: Add a dedicated @FieldWidget annotation WidgetFactory is dead code.
Adding a dummy create(), a la EntityFormController, as a guide for anyone that decides to implement ContainerFactoryPluginInterface.
Comment #2
yched commentedRight, WidgetFactory is not actually used anymore (WidgetPluginManager sets
$this->factory = new WidgetFactory, but since it also provides its own createInstance() method, $this->factory is actually never used), and we should have removed the code in #2035315: Add a dedicated @FieldWidget annotation.Comment #3
alexpottNeeds a reroll
Comment #4
oriol_e9gComment #6
oriol_e9gCore is moving fast!
Comment #7
pcambraShouldn't this have a comment block? Apparently it had inheritdoc but probably doesn't make sense anymore
Comment #8
tim.plunkettGot lost since my patch. And yes, its still correct.
Comment #9
dawehnerI don't get that change. Why do we need the create() method on the WidgetBase which does not implement the ContainerFactoryPluginInterface at all? If someone needs it in their own custom widget, all they need is that interface. Formatters are pretty much doing the same.
Comment #10
tim.plunkettI'm doing that here because the dividing up of $configuration to satisfy the constructor is confusing, and it provides an example more than anything. It's to help illustrate what you need to do, taking the place of
I don't care that much though. We could force the interface here, or just leave this out and make every injection-needing widget figure that weirdness out...
Comment #11
tim.plunkettDiscussed this further with @dawehner in IRC, this is much cleaner.
Comment #12
dawehnerNice! This improves the DX a bit . Do we have to tag that as API change?
Comment #13
tim.plunkettYes, though it is not widespread, and returns the signature to match that of PluginBase, and almost every other plugin. We need to fix FormatterBase next.
Comment #14
amateescu commentedWait, what? What's going on here? Why would every plugin need to match the signature or PluginBase?
At least, let's please give a bit more than three minutes to a field api maintainer to see these changes..
Comment #16
tim.plunkettIt doesn't have to match. But it is nice to.
Otherwise, every single widget that needs services injected will need to know the magical keys of $configuration['field_definition'] and $configuration['settings'] when implementing ControllerInterface::create(). That's a problem.
Comment #17
amateescu commentedHm.. I thought the plugin system was all about flexibility. Silly me :)
Setting back to NR for Yves.
Comment #18
tim.plunkettIt was all fine until we needed injection. Passing the burdens of flexibility onto the plugin implementations themselves is not cool.
Comment #19
amateescu commentedI would tell you what I'd do with that injection, but this is a public issue queue :)
Comment #20
yched commentedI'm not sure I like this change either.
Widgets are objects that need a $field_definition and an array of $settings. That's what their current constructor signature expresses.
They happen to be mostly instantiated though the plugin system, but that should not force the shape of their constructor.
Having a "fixed" signature imposed, with all "interesting" arguments (those specific to the plugin type aka the business logic at hand) packed into a $configuration array that the constructor then needs to unpack seems really wrong.
$configuration is Plugin-lingo, it's the format used by FactoryInterface::createInstance() just so that there *can* be a method with a fixed signature in an interface.
I'd much rather have that "unpacking of $configuration" done
- either in the Plugin-related system that calls create() (standalone factory or createInstance() method on the manager), as in HEAD,
- or in the create() method as in the initial iterations of this patch. create() is the interface between the Plugin system and the object, so having some Plugin-related "translation" is fine here.
But it should not bleed further down in the plugin implementation class IMO.
Comment #23
yched commentedWidgetFactory is actually not used at all:
- WidgetPluginManager::__construct() does specify $this->factory = new WidgetFactory($this);
- but it also overrides DefaultPluginManager::createinstance() with custom code that doesn't use $this->factory (just like FormatterPluginManager does, it's code similar to Containerfactory but tailored for the specific constructors of Widgets). So there is no active code that actually ever does anything with $this->factory.
Patch removes WidgetPluginManager's $this->factory and the WidgetFactory class altogether.
Comment #24
yched commentedTo be more explicit : #23 brings WidgetPluginManager in line with FormatterPluginManager. If we want to change something in this area and have them use ContainerFactory instead of a custom implementation of createInstance(), it should happen on both sides - but as explained in #20, I'm not in favor of doing that
Comment #25
yched commentedRTBC anyone ?
Comment #26
amateescu commentedSure thing!
Comment #27
alexpottDead code is bug.
Committed 87cb9a6 and pushed to 8.0.x. Thanks!
Comment #28
alexpottAnd this turned out to not be an API change