protected function WebformAccessGroupStorage::doSave in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_access/src/WebformAccessGroupStorage.php \Drupal\webform_access\WebformAccessGroupStorage::doSave()
Performs storage-specific saving of the entity.
Parameters
int|string $id: The original entity ID.
\Drupal\Core\Entity\EntityInterface $entity: The entity to save.
Return value
bool|int If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides ConfigEntityStorage::doSave
File
- modules/
webform_access/ src/ WebformAccessGroupStorage.php, line 137
Class
- WebformAccessGroupStorage
- Storage controller class for "webform_access_group" configuration entities.
Namespace
Drupal\webform_accessCode
protected function doSave($id, EntityInterface $entity) {
/** @var \Drupal\webform_access\WebformAccessGroupInterface $entity */
$result = parent::doSave($id, $entity);
// Save admins.
$admins = $entity
->getAdminIds();
$this->database
->delete('webform_access_group_admin')
->condition('group_id', $entity
->id())
->execute();
$query = $this->database
->insert('webform_access_group_admin')
->fields([
'group_id',
'uid',
]);
$values = [
'group_id' => $entity
->id(),
];
foreach ($admins as $uid) {
$values['uid'] = $uid;
$query
->values($values);
}
$query
->execute();
// Save users.
$users = $entity
->getUserIds();
$this->database
->delete('webform_access_group_user')
->condition('group_id', $entity
->id())
->execute();
$query = $this->database
->insert('webform_access_group_user')
->fields([
'group_id',
'uid',
]);
$values = [
'group_id' => $entity
->id(),
];
foreach ($users as $uid) {
$values['uid'] = $uid;
$query
->values($values);
}
$query
->execute();
// Save entities.
$entities = $entity
->getEntityIds();
$this->database
->delete('webform_access_group_entity')
->condition('group_id', $entity
->id())
->execute();
$query = $this->database
->insert('webform_access_group_entity')
->fields([
'group_id',
'entity_type',
'entity_id',
'field_name',
'webform_id',
]);
$values = [
'group_id' => $entity
->id(),
];
foreach ($entities as $entity) {
list($values['entity_type'], $values['entity_id'], $values['field_name'], $values['webform_id']) = explode(':', $entity);
$query
->values($values);
}
$query
->execute();
return $result;
}