Problem/Motivation
As per Plugin types should use PHP attributes instead of annotationswe are now able to use PHP attributes instead of annotations.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork entity_browser-3522955
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
primsi commentedComment #4
berdirLets also do core plugin type conversions for fields, constraints and views, those should all be supported since 10.3, we can raise that from 10.2 that we already require anyway.
Comment #5
anybody+1 on #4 would be great if someone could improve the MR accordingly.
@primsi maybe?
Comment #6
velmir_taky commentedComment #7
velmir_taky commentedthanks @primsi for the groundwork (our own plugin types were already fully on attributes, with the managers wired for attribute + annotation BC).
Completed the core plugin type conversions @berdir asked for in #4 (all supported since 10.3, so raised the floor to
^10.3 || ^11):@FieldWidget=>#[FieldWidget]— EntityReferenceBrowserWidget, FileBrowserWidget (dropped the redundant explicitprovider, it's auto-derived);@Constraint=> removed the leftover annotation (the attribute was already there);@ViewsField=>#[ViewsField]— SelectForm, SearchApiSelectForm;@ViewsFilter=>#[ViewsFilter]— ContextualBundle;@ViewsArgumentDefault=>#[ViewsArgumentDefault]— EntityBrowserWidgetContext;@ViewsDisplay=> the views display plugin (see below).The views display was the only non-mechanical one: it carries a custom
entity_browser_display = TRUEproperty (used byViews::getApplicableViews()to find our displays), and the core#[ViewsDisplay]attribute has a fixed parameter list. So I added a small#[EntityBrowserViewsDisplay]attribute subclass that adds that one parameter and forwards the rest to core — same pattern core itself uses for itsentity_reference_displaymarker. Discovery picks the subclass up because core matches withReflectionAttribute::IS_INSTANCEOF, andAttributeBase::get()reflects the extra property into the definition.Left out of scope on purpose: the
@FormElementElement plugins are being converted in #3613186 (coupled to theFormElementBase/^10.3change there — doing them here too would just conflict), and the@ConfigEntityTypeon the entity is an entity type rather than a plugin.Comment #9
csakiistvanComment #10
csakiistvanEnvironment
da1f50c)Prerequisites
media_image_uploadwidget is only discovered when Media is installed):test_files,test_files1,test_files_ajax,test_nodes) covering the iFrame and Modal displays, and theentity_browser_testcontent type whose form uses five Entity Browser field widgets.8.x-2.xbranch.Steps
src/Attribute/, the six plugin managers are switched to attribute discovery, the core plugin types (FieldWidget, Constraint, Views field/filter/argument default/display) are converted as well, and the core requirement is raised to^10.3 || ^11.ddev drush cr/node/add/entity_browser_testand confirm that all five Entity Browser widgets render: Files (iFrame display), Files 1 (Modal display), Files over AJAX (iFrame), Image browser (file browser) and Nodes (iFrame)./admin/config/content/entity_browserand confirm every browser can be edited, with all display, widget selector, widget and selection display plugins listed in their select lists.Expected results
auto_select,entity_browser_display,entity_reference_display) as on the baseline branch.Actual results
The conversion works. All 26 plugin classes are on attributes with no annotation left, and every plugin type keeps its complete definition set: the three displays, three widgets (including
media_image_upload), three selection displays, three widget selectors, three widget validators, three field widget displays, the two field widgets, the Views display, field, filter and argument default plugins and the image dimensions constraint are all discovered, with the custom definition keys preserved. In the browser both before and after the change all five widgets on/node/add/entity_browser_testrender, the iFrame and Modal displays open, the widget selector tabs work and selected entities are returned to the field; the configuration forms are unaffected. Kernel tests pass (9 tests, 77 assertions); the reported deprecations come from Symfony and PHPUnit, not from the module. One regression was found and fixed on the MR branch: insrc/Plugin/EntityBrowser/FieldWidgetDisplay/RenderedEntity.phpthe attributedescriptionhad been copy-pasted fromImageThumbnailand readDisplays image files as thumbnailsinstead of the originalDisplays fully rendered entity.. It is not shown in the UI, since the field widget settings form only renders plugin labels, but the plugin definition was factually wrong, so it was restored in commitda1f50c("Issue #3522955: Restore the RenderedEntity plugin description"). After that commit the plugin definition set matches the baseline branch exactly.Unrelated to this issue: on the pages containing an entity browser view, the admin theme logs a
Using null as an array offsetdeprecation fromviews-view-field--status.html.twig(Gin and core'sdefault_admin), becauserow.node_field_data_langcodeis empty in that view. This is present on the unmodified8.x-2.xbranch as well.Testing produced with the assistance of an LLM.
Comment #11
berdirdid a bit of cleanup on the attribute classes, found one unconverted plugin in the entity form submodule.
Comment #12
berdirAlso converted the entity type, the deriver is a a bit tricky on that extend views plugin, but we can just not call the parent. But I think we don't need that all. It's not nice, but we can use an alter hook to add that in, there is no other plugin in contrib that does that, it's a lot of code just to avoid the alter hook.
Comment #14
berdirMerged.
Comment #16
csakiistvanThanks @berdir for the lot of work