You are here

public function BlogapiCommunicator::getNodeCategories in Blog API 8

Returns taxonomy terms saved in the defined taxonomy field on a node.

Parameters

$nid: The node ID.

$user: Drupal username.

$pass: Drupal password.

Return value

array|object Returns either an error or terms.

File

src/BlogapiCommunicator.php, line 132

Class

BlogapiCommunicator
Class BlogapiCommunicator.

Namespace

Drupal\blogapi

Code

public function getNodeCategories($nid, $user, $pass) {

  // Check user authentication.
  $user = $this
    ->authenticate($user, $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);
  }
  $ct = $node
    ->getType();
  $taxonomy_fields = $this->blogapiConfig
    ->get('taxonomy_' . $ct);
  $taxonomy_terms = $this
    ->getTaxonomyTerms($node, [
    $taxonomy_fields,
  ]);
  return $taxonomy_terms;
}