-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provides plugin INSTANCES from Grav instance #2277
Conversation
Just provide (a way) to access current plugin INSTANCES..
To be honest, I'm strongly against allowing users to access plugins directly. Instead, the plugins should be implemented so that they provide services that you can use. |
Nor cleanness nor dirtiness are objectives by themselves. I understand anyone would prefer to have a nice and clean API with fences all around in order to protect users (actually: "developers") from shooting themselves in the foot, or to rely on methods that may disappear later, ... I also agree that granting plugin instance access is a necessary but not a sufficient condition. But a very important characteristic of a good software is to be able to be tweaked so that it fits our needs and not only in the common use-case that initial developers thought about. When such a real-world case happens to you, cleanness is worth nothing in comparison with resolving the problem. I'm sorry if this sound manichean, but that's a kind of Drupal vs WordPress issue. Please, just let me use my (plugin) data during the processing pipeline :) |
Yes, my main reason not allowing you to do that is that it's not considered to be part of API and your code can break on any release, including bugfix (+0.0.1) releases. The trend has been to make everything private or final so that you cannot even extend the classes anymore -- for the same reasons. This includes twig, Symfony and about every library I'm using. I've been customizing forms by page content or URL and I've never needed to access the plugin directly. Maybe there's already a way to do this? Let me comment to the another issue. |
The end-result is that instead of living with |
@drzraf You should already be able to get plugins by |
The last time I tried in 1.6 (years ago), I was only getting a stripped-down version of the object: The wrapping interface kept me from accessing particular plugins' methods and attributes. I'd be happy to know this limitation been removed in 1.7. |
… it easier to access plugin instances [#2277]
Added methods to get plugins by their name, not by class (as it already exists). BTW: there's no stripped-down version of the plugins.. They have always been the full objects. |
Don't consider users babies, save them digging stacktraces to find the data they need : Just provide a way to access currently initialized plugins INSTANCES.
Sample use-case:
form
(onFormPageHeaderProcessed
) does not make it because I want to know whether or not to add assets according to the form.(There would have many other legitimate use-case for accessing instance data)
Without this patch,
form
pluginforms
are unavailable. With it, there are just here: