
Problem/Motivation
After moving RenderElement and FormElement plugin discovery from annotations to attributes in #3421439: Convert form and render element plugin discovery to attributes, it has often become necessary in many element plugin implementation to import "RenderElement" or "FormElement" classes from two different namespaces for each plugin type:
\Drupal\Core\Render\Element\RenderElement
and\Drupal\Core\Render\Attribute\RenderElement
\Drupal\Core\Render\Element\FormElement
and\Drupal\Core\Render\Attribute\FormElement
This can have a negative impact on developer experience, because IDEs such as PHPStorm often do not provide typehint/autocomplete for the class name if a use statement was already added,or if the referenced class exists in the same namespace as the current one.
Additionally, \Drupal\Core\Render\Element\RenderElement
and\Drupal\Core\Render\Element\FormElement
are abstract classes, and there is convention in adding a "Base" suffix to these types of classes.
Suggestion here is to call these classes RenderElementBase and FormElementBase.
Steps to reproduce
Proposed resolution
- Create abstract class \Drupal\Core\Render\Element\RenderElementBase and move all the contents of \Drupal\Core\Render\Element\RenderElement there
- to Create abstract class \Drupal\Core\Render\Element\FormElementBase and move all the contents of \Drupal\Core\Render\Element\FormElement there
- Set \Drupal\Core\Render\Element\RenderElement to extend \Drupal\Core\Render\Element\RenderElementBase
- Set \Drupal\Core\Render\Element\FormElement to extend \Drupal\Core\Render\Element\FormElementBase
- Add deprecation messages for \Drupal\Core\Render\Element\RenderElement and \Drupal\Core\Render\Element\FormElement
- Add CR
Remaining tasks
User interface changes
API changes
- \Drupal\Core\Render\Element\RenderElement renamed to \Drupal\Core\Render\Element\RenderElementBase
- \Drupal\Core\Render\Element\FormElement renamed to \Drupal\Core\Render\Element\FormElementBase
No other changes
Data model changes
N/a
Release notes snippet
As this is a simple rename with the API left in place to Drupal 12 I don't think this warrants a release note.
Issue fork drupal-3431452
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:
- 3431452-rename-renderelement-and
changes, plain diff MR !7195
Comments
Comment #2
godotislateComment #3
godotislateComment #5
godotislateCreated CR: https://www.drupal.org/node/3436275
MR with updated test for deprecation: https://git.drupalcode.org/project/drupal/-/merge_requests/7195
Comment #6
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis actually seems like a large change, probably safer to deprecated for removal in D12
Comment #7
godotislateUpdated CR and MR to 12 for removal version.
Comment #8
smustgrave CreditAttribution: smustgrave at Mobomo commentedThanks appears to need manual rebasing though.
Comment #9
godotislateRebased and resolved conflict.
Comment #10
smustgrave CreditAttribution: smustgrave at Mobomo commentedTHanks conflict appears to be resolved.
Comment #11
godotislateThanks for reviewing.
Separately, I wish that there were a similar way to deal with validation Constraint plugins, since my guess is that there are a lot more contrib and custom validation plugins being written than render element plugins, but since Constraint is a Symfony class, not sure there's a solution.
Comment #12
alexpottAs things are called statically on the classes we need to issue deprecations from there too because this will avoid the constructor.
So for example we need to add things like
\Drupal\Core\Render\Element\FormElement::processPattern()
with the code:Not pretty but the best we can do.
Comment #13
godotislateAdded deprecation warnings to all the static methods with corresponding tests.
Comment #14
smustgrave CreditAttribution: smustgrave at Mobomo commentedWill remember that about static methods going forward
Deprecations look good though.
Comment #15
alexpott@godotislate thanks for getting this done. It's great to have this complete before people start to covert to attributes as it was pretty icky.
Committed and pushed 8d1ff20647 to 11.x and b89ad7f9c8 to 10.3.x. Thanks!
Comment #20
scott_euser CreditAttribution: scott_euser as a volunteer and at Soapbox commentedI guess it's not possible to backport empty RenderElementBase and FormElementBase classes to 10.2 that extend the old ones to allow contrib to fix depreciations now vs having to wait until end of 10.2 security coverage on December 9th? Happy to do the legwork there if it is an option but I guess it's not as no further non-security releases to 10.2 right?