public function BlogapiCommunicator::deletePost in Blog API 8
Callback for deleting a post.
Parameters
$nid: The node ID.
$user: Drupal user.
$pass: Drupal password.
Return value
bool|object The operation success.
File
- src/
BlogapiCommunicator.php, line 688
Class
- BlogapiCommunicator
- Class BlogapiCommunicator.
Namespace
Drupal\blogapiCode
public function deletePost($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 (!$this
->checkUserNodeAccess($user, $node)) {
return $this
->returnXmlError(self::BLOGAPI_XML_ERROR_NODE_UPDATE, $nid);
}
if (!$node
->access('delete', $user)) {
// User does not have permission to view the node.
return $this
->returnXmlError(self::BLOGAPI_XML_ERROR_NODE_DELETE, $nid);
}
$node
->delete();
return TRUE;
}