You are here

public function BlogapiCommunicator::getPost in Blog API 8

Returns a loaded node object.

Parameters

$nid: The node ID.

$username: Drupal username.

$pass: Drupal password.

Return value

object Either an error or a node object.

File

src/BlogapiCommunicator.php, line 605

Class

BlogapiCommunicator
Class BlogapiCommunicator.

Namespace

Drupal\blogapi

Code

public function getPost($nid, $username, $pass) {

  // Check user authentication.
  $user = $this
    ->authenticate($username, $pass, TRUE);
  if (!$user) {
    return $this
      ->returnXmlError(self::BLOGAPI_XML_ERROR_AUTH);
  }
  $node = $this->entityTypeManager
    ->getStorage('node')
    ->load($nid);
  if (!$node) {
    return $this
      ->returnXmlError(self::BLOGAPI_XML_ERROR_NODE_NOT_FOUND, $nid);
  }
  if (!$node
    ->access('view', $user)) {

    // User does not have permission to view the node.
    return $this
      ->returnXmlError(self::BLOGAPI_XML_ERROR_NODE_ACCESS, $nid);
  }
  return $node;
}