Problem/Motivation
Drupal has arrays.
Drupal has LOTS of arrays.
Arrays are, sometimes, quite painful to manipulate and test.
We need a base object that we can start creating other strongly typed objects on that do nothing but manipulate and extract information from arrays (at their core, no pun intended):
- Attributes (a better implementation)
- Attachments
- DrupalArray (base class the following two objects are extended from)
- Element (similar to #2316941: Use the builder pattern to make it easier to create render arrays)
- Variables (for templates)
- ... even more?
Additional use-cases for existing issues:
- #2316941: Use the builder pattern to make it easier to create render arrays
- #2863819: Convert theme hooks (defined by hook_theme()) to be objects
- #2941317: Theme Suggestion builder
- #2511548: Add a "context" array variable to all theme hooks and "#context" array property to all elements to provide optional contextual data (Needs mutable and immutable)
Unfortunately, the SPL \ArrayObject isn't really all that "feature rich" with all the various tasks that we commonly do with arrays.
Proposed resolution
Implement our own custom base ArrayObject class, similar to something that resembles:
https://cgit.drupalcode.org/plus/tree/src/Utility/ArrayObject.php?h=8.x-4.x
Remaining tasks
- Create patch
- Create tests
User interface changes
None
API changes
Utility/API addition
Data model changes
None