function public function Element::setProperty

8.x-3.x Element.php public Element::setProperty($name, $value, $recurse = FALSE, $forceString = NULL)

Sets the value for a property.

Parameters

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

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

bool $recurse: Flag indicating wither to set the same property on child elements.

bool $forceString: Optional. Forces the value to be appended as a string. By default, this is automatically determined based on the property name provided. Manually passing TRUE or FALSE will override any automatic determination.

Return value

static

See Also

Class

Element
Provides helper methods for Drupal render elements.

Namespace

Drupal\bootstrap\Utility

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

public function setProperty($name, $value, $recurse = FALSE, $forceString = NULL) {
  if (!isset($forceString)) {
    $forceString = static::isStringProperty($name);
  }

  if ($forceString) {
    $this->array["#$name"] = (string) Element::create($value)->renderPlain();
  }
  else {
    $this->array["#$name"] = $value instanceof Element ? $value->getArray() : $value;
  }
  if ($recurse) {
    foreach ($this->children() as $child) {
      $child->setProperty($name, $value, $recurse);
    }
  }
  return $this;
}