Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Currently, all plugins are available, even if the module and/or field type is not available. You get a fatal error on the add field screen, e.g.
Fatal error: Call to undefined function Drupal\dream_fields\Plugin\DreamField\image_style_options() in /home/drupal/drupal-core/modules/dream_fields/src/Plugin/DreamField/DreamFieldImage.php on line 33
This happens when the image module is not enabled.
The plugins should declare the dependency on the field type, I guess in the annotation (a bit like formatters and widgets do)
/**
* Plugin implementation of 'image'.
*
* @DreamField(
* id = "image",
* label = @Translation("Image"),
* description = @Translation("This will add an input field for a single image and will be outputted without a the label."),
* field_types = {
* "image"
* }
* )
*/
Comment | File | Size | Author |
---|---|---|---|
#9 | 2726317-plugins-use-provider.patch | 3.99 KB | Dave Reid |
Comments
Comment #2
attiks CreditAttribution: attiks at Attiks commentedWorking on a patch
Comment #4
attiks CreditAttribution: attiks at Attiks commentedLogic added to the form, although might be better inside the plugin manager?
Comment #5
attiks CreditAttribution: attiks at Attiks commentedFYI: Created an issue to add tests #2726955: Add testing
Comment #6
swentel CreditAttribution: swentel commentedI'd be safer to let the plugin manager figure this out yeah.
One other thing, shouldn't it be documented on the annotation too ?
Comment #7
attiks CreditAttribution: attiks at Attiks commentedYes and Yes, thanks
Comment #8
Dave ReidWhy not use the 'provider' annotation key to match it with the module providing the field type? That would remove the need for any additional or custom logic.
Comment #9
Dave ReidThis moves the information to the 'provider' key which just works natively with D8 plugins. And also fixes that the datetime field was missing the dependency information as well.
Comment #10
attiks CreditAttribution: attiks at Attiks commentedCool, thanks, it works. I was using provider to get the preview image, but will fix it using preview_provider key
Comment #13
attiks CreditAttribution: attiks at Attiks commentedJust discussed with @swentel and it feels like we're abusing the provider key, provider should be the module providing the plugin, and there might be a case where we have multiple dependencies, which can only be specified using an array
Comment #15
attiks CreditAttribution: attiks at Attiks commentedBack to the old situation, but moved the code to the plugin manager, findDefinitions
Comment #16
Dave ReidI figured for basic dependencies, use provider since the module provides the field type. The provider key was built in to core specifically to provide plugins conditionally based if a module is enabled or not, so it's using it exactly for the purpose it was built for, but oh well.
Comment #17
Dave ReidNote that with the reverts, DreamFieldLink.php is missing the dependency on the link field type again.
Comment #18
attiks CreditAttribution: attiks at Attiks commented#16 They explained it to me that the provider is the module providing the plugin
#17 Will add it again, thanks
Comment #19
Dave ReidThat is incorrect. See #2053153: Allow contrib modules to provide plugins on behalf of optional modules. Provider is only filled in with the module that provides it by default, but was meant to be used in this case.
Comment #20
Dave ReidAnd https://www.drupal.org/node/2218535 as the change record
Comment #21
attiks CreditAttribution: attiks at Attiks commentedThanks for the links, so back to NR, but my problem remains that I need to specify multiple dependencies, ex. the list of checkboxes can reference both terms and nodes, and depends on the option widget.
I'll check if your patch still applies and will add extra check on the modules.
Comment #23
attiks CreditAttribution: attiks at Attiks commentedSwitch back to using the provider, but left the field_types as well to have more control, probably not needed for core, but might be needed for contrib.
Thanks for explaining, learned something new!