public function BlogapiCommunicator::publishPost in Blog API 8
Method that sets a nodes status.
Parameters
$nid: The node ID.
$user: Drupal username.
$pass: Drupal password.
bool $publish: Boolean Drupal publish status.
Return value
bool|object A success bool.
File
- src/
BlogapiCommunicator.php, line 749
Class
- BlogapiCommunicator
- Class BlogapiCommunicator.
Namespace
Drupal\blogapiCode
public function publishPost($nid, $user, $pass, $publish = TRUE) {
$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 (!$this
->checkUserNodeAccess($user, $node)) {
return $this
->returnXmlError(self::BLOGAPI_XML_ERROR_NODE_UPDATE, $nid);
}
if (!$node
->access('edit', $user)) {
// User does not have permission to view the node.
return $this
->returnXmlError(self::BLOGAPI_XML_ERROR_NODE_UPDATE, $nid);
}
$node
->setPublished($publish);
return TRUE;
}