function AddComponent::apply
Applies the config action.
Parameters
string $configName: The name of the config to apply the action to.
mixed $value: The value for the action to use.
Overrides ConfigActionPluginInterface::apply
File
-
core/
modules/ layout_builder/ src/ Plugin/ ConfigAction/ AddComponent.php, line 89
Class
- AddComponent
- Adds a component to a layout builder section.
Namespace
Drupal\layout_builder\Plugin\ConfigActionCode
public function apply(string $configName, mixed $values) : void {
assert(is_array($values));
if ($this->multiple) {
assert(array_is_list($values));
}
else {
$values = [
$values,
];
}
$entity = $this->configManager
->loadConfigEntityByName($configName);
if (!$entity instanceof SectionListInterface) {
throw new ConfigActionException("No entity found for applying the addComponentToLayout action.");
}
foreach ($values as $value) {
$this->applySingle($entity, $value);
}
$entity->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.