You are here

public function ParagraphsTableFormatter::checkPermissionOperation in Paragraphs table 8

Check permission Operation.

2 calls to ParagraphsTableFormatter::checkPermissionOperation()
AjaxController::json in src/Controller/AjaxController.php
Return output JSON object value.
ParagraphsTableFormatter::viewElements in src/Plugin/Field/FieldFormatter/ParagraphsTableFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/ParagraphsTableFormatter.php, line 1102

Class

ParagraphsTableFormatter
Plugin implementation of the 'paragraphs_table_formatter' formatter.

Namespace

Drupal\paragraphs_table\Plugin\Field\FieldFormatter

Code

public function checkPermissionOperation($entity, $fieldName) {
  $hasPermission = FALSE;
  $user = \Drupal::currentUser();
  $permissions = [
    'bypass node access',
    'administer nodes',
    'administer paragraphs_item fields',
    'create ' . $fieldName,
    'edit ' . $fieldName,
    'edit own ' . $fieldName,
  ];
  foreach ($permissions as $permission) {
    if ($user
      ->hasPermission($permission)) {
      $hasPermission = TRUE;
      break;
    }
  }
  $entityType = $entity
    ->getEntityTypeId();
  if (!$hasPermission && $entityType != 'user') {
    $uid = $entity
      ->getOwnerId();
    if ($user
      ->hasPermission($permission) && $uid && $uid == $user
      ->id()) {
      $hasPermission = TRUE;
    }
  }
  return $hasPermission;
}