Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Spin-off from #1704196: Remove Config's dependencies on procedural Drupal code in includes/common.inc
Goal
- Replace all procedural
drupal_array_*()
function calls with static methods on theDrupal\Component\Utility\NestedArray
class.
Challenge
- Update all of these calls throughout Drupal core accordingly:
- drupal_array_merge_deep_array($arrays) { + NestedArray::mergeDeepArray($arrays); - drupal_array_get_nested_value(array &$array, array $parents, &$key_exists = NULL) { + NestedArray::getValue($array, $parents, $key_exists); - drupal_array_set_nested_value(array &$array, array $parents, $value, $force = FALSE) { + NestedArray::setValue($array, $parents, $value, $force); - drupal_array_unset_nested_value(array &$array, array $parents, &$key_existed = NULL) { + NestedArray::unsetValue($array, $parents, $key_existed); - function drupal_array_nested_key_exists(array $array, array $parents) { + NestedArray::keyExists($array, $parents);
- Make sure that each of the files that uses NestedArray contains this use statement:
use Drupal\Component\Utility\NestedArray;
This should be at the top of the file. If there is a namespace declaration, it must be below that. If there are other use statements already, add it in the alphabetical order (but do not change other use statements, if they are incorrect).
- Remove the procedural functions (entirely).
Comment | File | Size | Author |
---|---|---|---|
#26 | drupal8.nestedarray.26.patch | 41.79 KB | underq |
#24 | drupal8.nestedarray.24.patch | 41.8 KB | underq |
#20 | drupal8.nestedarray.20.patch | 35.31 KB | sun |
#15 | drupal-1705920-15.patch | 35.32 KB | tim.plunkett |
#11 | drupal8.nestedarray.11.patch | 35.5 KB | sun |
Comments
Comment #1
tim.plunkett#1704196: Remove Config's dependencies on procedural Drupal code in includes/common.inc is in.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedDone.
Comment #6
tim.plunkettPatch was partially malformed, and had on windows line ending. After I got it to apply, all of drupal_array was gone.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commented@tim.plunkett: I' m tired of Eclipse ( i think it is him, not me) adding \r newlines, or creating wrong patches. Maybe i'm not using it correctly... anyway, could you tell me a tool for checking this previosly to attaching here ? I'm using dreditor, but i cant see those windows line endings on the "Review" tool.
Thanks!
Comment #8
tim.plunkettHm, dreditor doesn't pick those up (feature request!), I just noticed it in vim while looking through the patch.
That said, the patch looks good and just passed!
Comment #9
sunThese aren't added in alphabetical order.
It looks like we could and should merge that überwonky MiscUnitTest into ArrayUnitTest? (or at least the array-merge parts of it, if there's more "misc" stuff in that crappy test case...)
Comment #10
tim.plunkettPutting
use
statements in alphabetical order isn't in our coding standards (yet). Maybe open an issue to discuss adding that to http://drupal.org/node/1353118?That would leave testCheckMemoryLimit() all alone in MiscUnitTest :)
Comment #11
sunI know that the order of use statements is not defined in the coding standards yet, but I wrote the issue summary and specifically asked to add them in alphabetical order - at least for the time being that seems to be the most natural and sensible approach, in order to not significantly increase the havoc.
Performed the final adjustments.
Also renamed ArrayUnitTest into NestedArrayUnitTest.
Comment #12
tim.plunkettRe-RTBC then.
Comment #13
catch#11: drupal8.nestedarray.11.patch queued for re-testing.
Comment #15
tim.plunkettRerolled.
Comment #16
amonteroHow does this relates to #66183: Add helper methods to inject items into a particular position in associative arrays?
Comment #17
sunThanks, looks good!
@amontero: Doesn't seem to relate at all to that issue.
Comment #18
sun#15: drupal-1705920-15.patch queued for re-testing.
Comment #20
sunRe-rolled against HEAD.
Comment #21
amontero#20: drupal8.nestedarray.20.patch queued for re-testing.
Comment #23
amonteroTagging
Comment #24
underq CreditAttribution: underq commentedOk rerolled :)
Comment #25
amonteroThanks!! The reroll seems OK to me.
Lame nitpick: at line 727 of patch, the comment "Tests the various NestedArray helper class." seems a bit weird to me, sun's original patch deleted "various". But seems not worth to set it to "needs work". At least until no other problems have been ruled out.
Untagging.
Comment #26
underq CreditAttribution: underq commentedI removed "various" and rerolled patch :)
Comment #27
amonteroThanks. Tagging.
Comment #28
tim.plunkettLooks good. See also #1356170: Remove all uses of array_merge_recursive, or document why they are being used instead of NestedArray::mergeDeep()
Comment #29
amonteroThis one was also postponed:
#66183: Add helper methods to inject items into a particular position in associative arrays
Comment #30
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks.
Comment #31
catchThis could use a change notification.
Comment #32
tim.plunkettAdded http://drupal.org/node/1870678 and updated http://drupal.org/node/1403768
Comment #33.0
(not verified) CreditAttribution: commentedUpdated issue summary.