function public function Element::appendProperty

8.x-3.x Element.php public Element::appendProperty($name, $value)

Appends a property with a value.

Parameters

string $name: The name of the property to set.

mixed $value: The value of the property to set.

Return value

static

Class

Element
Provides helper methods for Drupal render elements.

Namespace

Drupal\bootstrap\Utility

Source src/Utility/Element.php (line 159)

public function appendProperty($name, $value) {
  $property = &$this->getProperty($name);
  $value = $value instanceof Element ? $value->getArray() : $value;

  // If property isn't set, just set it.
  if (!isset($property)) {
    $property = $value;
    return $this;
  }

  if (is_array($property)) {
    $property[] = Element::create($value)->getArray();
  }
  else {
    $property .= (string) $value;
  }

  return $this;
}