QuickEditEntityFieldAccessCheck.php in Drupal 10
File
core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheck.php
View source
<?php
namespace Drupal\quickedit\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Entity\EntityInterface;
class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntityFieldAccessCheckInterface {
public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) {
if (!$this
->validateRequestAttributes($entity, $field_name, $langcode)) {
return AccessResult::forbidden();
}
return $this
->accessEditEntityField($entity, $field_name);
}
public function accessEditEntityField(EntityInterface $entity, $field_name) {
return $entity
->access('update', NULL, TRUE)
->andIf($entity
->get($field_name)
->access('edit', NULL, TRUE));
}
protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode) {
if (!$field_name || !$entity
->hasField($field_name)) {
return FALSE;
}
if (!$langcode || !$entity
->hasTranslation($langcode)) {
return FALSE;
}
return TRUE;
}
}