function RenderElementBase::addChild
Adds a child render element.
Parameters
int|string $name: The name of the child. Can also be an integer when the child is a delta.
array|\Drupal\Core\Render\Element\ElementInterface $child: A render array or a render object.
Return value
\Drupal\Core\Render\Element\ElementInterface The added child as a render object.
Overrides ElementInterface::addChild
1 call to RenderElementBase::addChild()
- RenderElementBase::createChild in core/
lib/ Drupal/ Core/ Render/ Element/ RenderElementBase.php - Creates a render object and attaches it to the current render object.
File
-
core/
lib/ Drupal/ Core/ Render/ Element/ RenderElementBase.php, line 664
Class
- RenderElementBase
- Provides a base class for render element plugins.
Namespace
Drupal\Core\Render\ElementCode
public function addChild(string|int $name, ElementInterface|array &$child) : ElementInterface {
if ($name[0] === '#') {
throw new \LogicException('The name of children can not start with a #.');
}
$childObject = $this->elementInfoManager()
->fromRenderable($child);
$childObject->renderParent = $this;
$childObject->renderParentName = $name;
$this->storage[$name] =& $childObject->toRenderable();
return $childObject;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.