public static function Webform::preCreate in Webform 8.5
Same name and namespace in other branches
- 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::preCreate()
Changes the values of an entity before it is created.
Load defaults for example.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
mixed[] $values: An array of values to set, keyed by property name. If the entity type has bundles the bundle key has to be specified.
Overrides EntityBase::preCreate
File
- src/
Entity/ Webform.php, line 2165
Class
- Webform
- Defines the webform entity.
Namespace
Drupal\webform\EntityCode
public static function preCreate(EntityStorageInterface $storage, array &$values) {
/** @var \Drupal\webform\WebformAccessRulesManagerInterface $access_rules_manager */
$access_rules_manager = \Drupal::service('webform.access_rules_manager');
$values += [
'status' => \Drupal::config('webform.settings')
->get('settings.default_status'),
'uid' => \Drupal::currentUser()
->id(),
'settings' => static::getDefaultSettings(),
'access' => $access_rules_manager
->getDefaultAccessRules(),
];
// Convert boolean status to STATUS constant.
if ($values['status'] === TRUE) {
$values['status'] = WebformInterface::STATUS_OPEN;
}
elseif ($values['status'] === FALSE) {
$values['status'] = WebformInterface::STATUS_CLOSED;
}
elseif ($values['status'] === NULL) {
$values['status'] = WebformInterface::STATUS_SCHEDULED;
}
}