function EntityClone::apply
Overrides ConfigActionPluginInterface::apply
File
-
core/
lib/ Drupal/ Core/ Config/ Action/ Plugin/ ConfigAction/ EntityClone.php, line 45
Class
- EntityClone
- @internal This API is experimental.
Namespace
Drupal\Core\Config\Action\Plugin\ConfigActionCode
public function apply(string $configName, mixed $duplicate_id) : void {
assert(is_string($duplicate_id));
// If the original doesn't exist, there's nothing to clone.
$original = $this->configManager
->loadConfigEntityByName($configName);
if (empty($original)) {
throw new ConfigActionException("Cannot clone '{$configName}' because it does not exist.");
}
$clone = $original->createDuplicate();
$clone->set($original->getEntityType()
->getKey('id'), $duplicate_id);
// Use the config action manager to invoke the `entity_create` action on
// the clone, so that it will be validated.
$this->configActionManager
->applyAction('entity_create:createIfNotExists', $clone->getConfigDependencyName(), $clone->toArray());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.