Currently, you have to implement an empty class for any local action plugin. This is a bit weird, you are then just using the empty class for the annotation. It makes sense, similar to routes, to have YAML discovery for these, then static local actions just get added into a $module.local_actions.yml file. This seems like better UX, as people can then actually create a plugin class for dynamic local actions.
Here is a rough initial patch, to get things rolling. No tests yet. It contains one conversion of the views UI add view link.
Also, the name StaticLocalActionDeriver is the first thing that came into my head, so thoughts on better names for that are most welcome and... I think it would might make sense to move getRouteName() and getTitle() methods from LocalActionBase into this new class?
Comment | File | Size | Author |
---|---|---|---|
#53 | 2050227-53.patch | 6.9 KB | damiankloip |
#53 | interdiff-2050227-53.txt | 579 bytes | damiankloip |
#47 | 2050227-47.patch | 6.9 KB | pwolanin |
#47 | 2050227-45-47.increment.txt | 1.04 KB | pwolanin |
#45 | 2050227-45.patch | 6.92 KB | pwolanin |
Comments
Comment #1
fubhy CreditAttribution: fubhy commentedDude, what's with these weird unrelated changes. Maaaan!
No... Just... No.
No, no, no...
Comment #2
damiankloip CreditAttribution: damiankloip commentedThanks! All valid comment related screw ups. I will see how tests get on, then reroll in a bit.
Comment #3
pwolanin CreditAttribution: pwolanin commentedSeems like we need a more generic framework for using yaml to define other-wise empty class definitions as derivatives of a base class?
Comment #4
damiankloip CreditAttribution: damiankloip commentedThat should be taken care of elsewhere, at the moment we don;t have that, So that shouldn't hold this up. The current (rushed) implementation is going to have a whole load of empty classes if we leave it...
So I think it makes sense to move the methods I mentioned above into the new plugin class. This only really makes sense if we're using static titles anyway.
EDIT: wrong patch comment #...
Comment #5
damiankloip CreditAttribution: damiankloip commentedSorry, the getRoutename() method doesn't make sense to move aswell.
Comment #6
fubhy CreditAttribution: fubhy commentedChanging the base class now is an API change. Let's not do that.
Comment #7
damiankloip CreditAttribution: damiankloip commentedThat thought didn't even cross my mind, you're right. Let's make this as easy as possible. I will leave it a bit and let the bot get on with its business.
Comment #9
damiankloip CreditAttribution: damiankloip commentedLet's move that method back.
Comment #10
dawehnerOhhh I would have assumed it to use a different discovery mechanism. This one then could have been reused on local tasks as well.
Comment #11
fubhy CreditAttribution: fubhy commentedTogether with #2050289: Add class to make yaml discovery reusable I think the approach of using a derivative is better. Not sure why, I just find it nice :).
Comment #12
dawehnerHaving multiple way to define such way potentially confuses people.
On the other hand doing it like it is proposed here, would really easy allow us to not change the API for now.
Comment #13
fubhy CreditAttribution: fubhy commentedWhy remove that damiboy? :(
inheritdoc please, bro.
Maybe add issue number?
Otherwise looking good! Thanks!
Comment #14
damiankloip CreditAttribution: damiankloip commentedThanks for the review fubhy, I've made those changes.
Daniel: I think this will have alot of similarities to what we do with routes, and services, so from a DX point of view I think this is a good thing. People will have to do the same, if they want to dynamically add routes, for example. Well, not plugins, but you know what I mean. This makes it alot easier to define simple actions; as well as not having lots of plugin classes just being used for their definition - this is pretty much what derivatives are for right? :)
Comment #15
dawehnerI don't disagree with the better/easier DX at the moment, but I want to raise the point that having two basically equal levels will maybe confuse people.
Comment #16
fubhy CreditAttribution: fubhy commentedYou mean because you can provide a 'static' local action by providing a empty annotation class or a yaml file? Well, we can't really prevent that from happening, can we? Not without breaking the API at least.
I think this is good to go. Let's do the same for local tasks.
Comment #17
fubhy CreditAttribution: fubhy commented#2050919: Replace local task plugin discovery with YamlDiscovery
Now that I think of it, should we do local tasks and actions with a single .yml file instead of two?
Comment #18
damiankloip CreditAttribution: damiankloip commentedI'm not sure about that right now, I haven't given it much thought. Certainly something worth considering though. I think we should move in easy stages, and see how we get on with this patch and the issue in #17, then talk about potential considation maybe?
Comment #19
pwolanin CreditAttribution: pwolanin commentedIf we are going this we should make sure the discovery code is generic and use it as well for local tasks
Comment #20
damiankloip CreditAttribution: damiankloip commented@pwolanin, see the @todo in the patch, and #2050289: Add class to make yaml discovery reusable.
If we want to share any more code than that I would suggest a follow up to do this to local actions/tasks in general as it looks like the LocalACtionBase and LocalTaskBase plugin classes have alot of duplicate code too.
Comment #21
alexpottLet's do this @todo now that #2050289: Add class to make yaml discovery reusable is in...
Edit: removed duplicated comment
Comment #22
damiankloip CreditAttribution: damiankloip commentedYep, Let's do that.
Comment #24
alexpottMissing a use statement for Drupal\Component\Discovery\YamlDiscovery
Comment #25
damiankloip CreditAttribution: damiankloip commentedDuh! thanks :)
Comment #26
dawehnerI think it is pointless to have a local action without a route/title
Comment #27
damiankloip CreditAttribution: damiankloip commentedMe and dawehner spoke briefly about this on IRC, It doesn't make sense if any of these keys aren't present. So let's just assume they are.
Comment #28
dawehnerSorry but it seems to be that we should typehint TranslationManager, as the method we use (translate()) is just defined on that one.
Comment #29
tim.plunkett#2049709: TranslationManager::translate() should be on an interface
Comment #30
damiankloip CreditAttribution: damiankloip commentedSo this patch should stay how it is in light of that? or we should change it now and that issue should change it back for us, depending on the outcome?
Comment #31
tim.plunkettJust that whichever you do, there's a good chance you'll be wrong :)
Comment #32
dawehnerHehe!
Comment #33
damiankloip CreditAttribution: damiankloip commentedSo, for now, we should just type hint TranslationManager.
Comment #34
damiankloip CreditAttribution: damiankloip commentedWe could also add this to the LocalActionTest.
Comment #35
dawehnerEven I personally think it is wrong to provide two different basic discovery mechanisms for a plugin type the patch is fine. We are sort of in a state where an API break should better be avoided.
Comment #36
fubhy CreditAttribution: fubhy commentedI don't think it's wrong to provide different discovery mechanism. Technically that is always possible anyways. Developers are not stupid either. You can even use static to provide a dynamic discovery derivative definition, Uh yeah... Umh. Anyways, this is totally fine. We have different discovery mechanisms all over the place (for the same things). Think about route definitions (dynamic / yaml based). That's actually exactly the same except that dynamic is event driven, not annotation driven...
So, RTBC+1 (personally thinking that this is perfectly fine) :).
Comment #37
EclipseGc CreditAttribution: EclipseGc commentedThis bugs me a bit. You've got the local_action info but you're throwing anything that doesn't match to your expected parameters away, and that's not really how this works. Usually you want to do something more like $this->derivatives[$name] = $info + $base_plugin_definition;
As an example, you're completely disregarding what the yml said with regard to provider. If you look at Core's Annotation discovery we only fill out provider if it's not already populated. Likewise, plugin definitions can have other stuff hung off them for unanticipated use cases, and you've completely eliminated the possibility for that in any instance other than drupal_alter usage.
That aside, I'm very ++ to this. I wouldn't worry about the "multiple ways to do something" as that's a side effect of allowing derivatives into your plugin type in the first place. Most derivatives utilize the UI to define plugins, but this is just as valid (in fact Layout plugins do exactly this already and have for a very long time now). More power to you.
Eclipse
Comment #38
damiankloip CreditAttribution: damiankloip commentedThat's a really good point, we don't know what other data people might might to hang off of this. Also, the provider is a good point which I totally overlooked :)
OK, new patch which should appease your concerns?
Comment #39
dawehnerMhh we should tell people if either the route_name or title is missing they are doing something wrong?
Comment #40
EclipseGc CreditAttribution: EclipseGc commentedre: 38
Yes that definitely solves my objections.
Eclipse
Comment #41
tim.plunkettSee also #2061777: Provide dynamic registration of local_action plugins
Comment #42
dawehner.
Comment #43
pwolanin CreditAttribution: pwolanin commentedper dawahner - throws an exception if the definition is invalid.
Comment #44
damiankloip CreditAttribution: damiankloip commentedHow is appears_on ever not going to be an array? as it's set as an array first.
Can't we do something a bit more informative, like this?
Comment #45
pwolanin CreditAttribution: pwolanin commented@damiankloip - well, even from the yaml it could be a string instead of an array?
Should we at least cast it to array?
We should supply it if missing.
Comment #46
damiankloip CreditAttribution: damiankloip commentedWhatever. I don't mind.
There is no point in adding appears_on to the defaults as the the exception will catch it first.
Comment #47
pwolanin CreditAttribution: pwolanin commentedoops, I think we should supply it?
Well, either way - if you want it to be empty, you can use
[]
in yamlComment #48
dawehnerI really like the current version, as it is way easier to read than previous versions!
Comment #49
tim.plunkett+1
Comment #50
damiankloip CreditAttribution: damiankloip commentedSmall thing, why the empty line between the use statements? iirc we haven't really been doing this.
Comment #51
pwolanin CreditAttribution: pwolanin commented@damiankloip - at least at one point we were doing it to separate symfony vs. Drupal classes, though not sure if it's been standardized.
Comment #52
EclipseGc CreditAttribution: EclipseGc commentedIt's worth pointing out that the LocalAction Annotation class is already setting appears_on to an empty array, so you're going to get some sort of mismatch error if someone tries to pass a string in there based upon the derivative code that's adding the base plugin definition and the plugin definition from the yaml together. Just wanted to draw attention to that aspect. This code seems to have that covered as well, but no one had mentioned it. ++ing the rtbc.
Eclipse
Comment #53
damiankloip CreditAttribution: damiankloip commentedWell, from my experience we've just been keeping them together/uniform, so we might as well.
Keeping rtbc as I'm only removing a line.
Comment #55
damiankloip CreditAttribution: damiankloip commented#53: 2050227-53.patch queued for re-testing.
Comment #56
damiankloip CreditAttribution: damiankloip commentedComment #57
catchLooks like a good change to me. Committed/pushed to 8.x, thanks!
Comment #58
webchickJust being the tag fairy, don't mind me. :D
Comment #59
dawehnerAdapted the change notice https://drupal.org/node/2007444/revisions/view/2768137/2801357
Comment #60
pwolanin CreditAttribution: pwolanin commentedShould be revised to use #2065571: Add YAML Plugin discovery?
Comment #61
damiankloip CreditAttribution: damiankloip commentedWell, as discussed in the other issue, we need to get the OK to have that api change. Otherwise that's irrelevant.
Either way, I think we should start a new issue if/when we need to.
Comment #62
catch#2083415: [META] Write up all outstanding change notices before release
Comment #62.0
catchUpdated issue summary.
Comment #63
star-szrDefinitely time to close this one, the change notice at https://drupal.org/node/2007444 is looking good. Besides the revision by @dawehner last August we also have an extensive change by @pwolanin in October: https://drupal.org/node/2007444/revisions/view/2801357/2861533.