public function Webform::createDuplicate in Webform 8.5
Same name and namespace in other branches
- 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::createDuplicate()
Creates a duplicate of the entity.
Return value
static A clone of $this with all identifiers unset, so saving it inserts a new entity into the storage system.
Overrides ConfigEntityBase::createDuplicate
File
- src/
Entity/ Webform.php, line 2118
Class
- Webform
- Defines the webform entity.
Namespace
Drupal\webform\EntityCode
public function createDuplicate() {
/** @var \Drupal\webform\WebformInterface $duplicate */
$duplicate = parent::createDuplicate();
// Clear path aliases, which must be unique.
$duplicate
->setSetting('page_submit_path', '');
$duplicate
->setSetting('page_confirm_path', '');
// Update owner to current user.
$duplicate
->setOwnerId(\Drupal::currentUser()
->id());
// If template being used to create a new webform, clear description
// and remove the template flag.
// @see \Drupal\webform_templates\Controller\WebformTemplatesController::index
$is_template_duplicate = \Drupal::request()
->get('template');
if ($duplicate
->isTemplate() && !$is_template_duplicate) {
$duplicate
->set('description', '');
$duplicate
->set('template', FALSE);
}
// If archived, remove archive flag.
if ($duplicate
->isArchived()) {
$duplicate
->set('archive', FALSE);
}
// Set default status.
$duplicate
->setStatus(\Drupal::config('webform.settings')
->get('settings.default_status'));
// Remove enforce module dependency when a sub-module's webform is
// duplicated.
if (isset($duplicate->dependencies['enforced']['module'])) {
$modules = WebformReflectionHelper::getSubModules();
$duplicate->dependencies['enforced']['module'] = array_diff($duplicate->dependencies['enforced']['module'], $modules);
if (empty($duplicate->dependencies['enforced']['module'])) {
unset($duplicate->dependencies['enforced']['module']);
if (empty($duplicate->dependencies['enforced'])) {
unset($duplicate->dependencies['enforced']);
}
}
}
return $duplicate;
}