Problem/Motivation

When using 2 different "sources" of attributes (example: a UIP2 source plugin + UI Styles), the values are not always merged correctly.

Proposed resolution

On UIP2 source plugin: don't send non-empty array value when empty string

On ComponentElementAlter::processAttributesRenderProperty() merge recursive to also merge the HTML classes.

Command icon 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

pdureau created an issue. See original summary.

pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Active » Needs review
just_like_good_vibes’s picture

seems nice, but i just wonder if "array_merge_recursive" is really enough to cover all the cases.

pdureau’s picture

Assigned: just_like_good_vibes » pdureau
Status: Needs review » Needs work

There are 2 levels in an attribute array:

  • The attribute array has only string, integer, float, or (list) array as values
  • The second level has only string, integer or float as values.

Example:

href: "/"
rel:
 - author 
 - creator
size: 4
class:
 - foo 
 - bar

12 HTML attributes expects a list as value according to https://html.spec.whatwg.org/#unordered-set-of-unique-space-separated-to...

Set of space-separated tokens:

  • class
  • ping

Unordered set of unique space-separated tokens:

  • blocking
  • for
  • headers
  • itemprop
  • itemref
  • itemtype
  • rel

Ordered set of unique space-separated tokens:

  • accesskey

Unordered set of unique space-separated tokens, ASCII case-insensitive:

  • sandbox
  • sizes

So, because it is a mess, I am proposing to follow what https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%... is doing:

    public function merge(Attribute $collection) {
        $merged_attributes = NestedArray::mergeDeep($this->toArray(), $collection->toArray());
        foreach ($merged_attributes as $name => $value) {
            $this->storage[$name] = $this->createAttributeValue($name, $value);
        }
        return $this;
    }

See: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Util...

pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Needs work » Needs review

  • pdureau committed 023c7299 on 2.0.x
    Issue #3482208 by pdureau: Fix attributes merging
    
pdureau’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs review » Fixed
pdureau’s picture

Status: Fixed » Closed (fixed)