Created
April 22, 2014 19:41
-
-
Save mortendk/11191799 to your computer and use it in GitHub Desktop.
merging attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$variables['attributes']['class'] = 'test-attribute-merge-1'; | |
$variables['content_attributes']['class'] ='test-content_attributes-merge-2'; | |
$variables['attributes']['role'] = 'attributes-role'; | |
$variables['content_attributes']['role'] = 'content_attributes-role'; | |
$variables['title_attributes']['role'] = 'title-attributes-role'; | |
$variables['item_attributes']['0']['role'] = 'item-attributes-role'; | |
//wtf why u not merge | |
$variables['attributes_test'] = NestedArray::mergeDeepArray(array( | |
$variables['attributes'], | |
$variables['content_attributes'], | |
$variables['title_attributes'] | |
) | |
); |
yup thats exactly what i was getting
Now I don't know the Drupal API but my guess is that there is no method for what you need. Would be pretty useful for a web CMS that has to deal with HTML attributes. :)
Edit: Rereading this might come over a bit unfriendly but isn't meant that way. This kind of merging is pretty difficult because it's hard to define what you expect. Basically for this kind of merging you can only reasonably work with one level of nesting.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do you expect as result? Same keys will override with priority to the last given argument. You won't get a joined 'roles' key with all roles that you assigned if that is what you are looking for.
At least that is what I get from a quick look at the method.