Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Field/FieldUpdateActionBase.php
- 9 core/lib/Drupal/Core/Field/FieldUpdateActionBase.php
Namespace
Drupal\Core\Field
File
core/lib/Drupal/Core/Field/FieldUpdateActionBase.php
View source
<?php
namespace Drupal\Core\Field;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;
abstract class FieldUpdateActionBase extends ActionBase {
protected abstract function getFieldsToUpdate();
public function execute($entity = NULL) {
foreach ($this
->getFieldsToUpdate() as $field => $value) {
$entity->{$field} = $value;
}
$entity
->save();
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = $object
->access('update', $account, TRUE);
foreach ($this
->getFieldsToUpdate() as $field => $value) {
$result
->andIf($object->{$field}
->access('edit', $account, TRUE));
}
return $return_as_object ? $result : $result
->isAllowed();
}
}
Classes