You are here

public function AjaxToggleForm::checkEditFieldAccess in Toggle Editable fields 8

Check only the access of the 'edit' operation for current field.

Return value

bool True if current user can edit that field or FALSE.

3 calls to AjaxToggleForm::checkEditFieldAccess()
AjaxToggleForm::buildForm in src/Form/AjaxToggleForm.php
Form constructor.
AjaxToggleForm::fieldIsEditable in src/Form/AjaxToggleForm.php
Check if the combo of entity + field access are satisfased.
AjaxToggleForm::updateFieldValue in src/Form/AjaxToggleForm.php
Update the clicked field with given value.

File

src/Form/AjaxToggleForm.php, line 208

Class

AjaxToggleForm
Build a form to switch state of targeted FieldItem.

Namespace

Drupal\toggle_editable_fields\Form

Code

public function checkEditFieldAccess() {
  $permission_type = $this->fieldDefinition instanceof FieldConfigInterface ? $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->getThirdPartySetting('field_permissions', 'permission_type') : NULL;
  $field_access = \Drupal::entityTypeManager()
    ->getAccessControlHandler($this->entity
    ->getEntityTypeId())
    ->fieldAccess('edit', $this->fieldDefinition, \Drupal::currentUser(), $this->fieldItem
    ->getParent());
  if ($field_access && empty($permission_type)) {
    return $this->entity
      ->access('update');
  }
  return $field_access;
}