You are here

protected function FeedsNodeProcessor::entitySaveAccess in Feeds 8.2

Check that the user has permission to save a node.

Overrides FeedsProcessor::entitySaveAccess

File

lib/Drupal/feeds/Plugin/feeds/processor/FeedsNodeProcessor.php, line 102
Contains \Drupal\feeds\Plugin\feeds\fetcher\FeedsNodeProcessor.

Class

FeedsNodeProcessor
Defines a node processor.

Namespace

Drupal\feeds\Plugin\feeds\processor

Code

protected function entitySaveAccess($entity) {

  // The check will be skipped for anonymous nodes.
  if ($this->config['authorize'] && !empty($entity->uid)) {
    $author = user_load($entity->uid);

    // If the uid was mapped directly, rather than by email or username, it
    // could be invalid.
    if (!$author) {
      $message = 'User %uid is not a valid user.';
      throw new FeedsAccessException(t($message, array(
        '%uid' => $entity->uid,
      )));
    }
    if (empty($entity->nid) || !empty($entity->is_new)) {
      $op = 'create';
      $access = node_access($op, $entity->type, $author);
    }
    else {
      $op = 'update';
      $access = node_access($op, $entity, $author);
    }
    if (!$access) {
      $message = 'User %name is not authorized to %op content type %content_type.';
      throw new FeedsAccessException(t($message, array(
        '%name' => $author->name,
        '%op' => $op,
        '%content_type' => $entity->type,
      )));
    }
  }
}