You are here

protected function DataProviderComment::setPropertyValues in RESTful 7.2

Overrides DataProviderEntity::setPropertyValues().

Set nid and node type to a comment.

Note that to create a comment with 'post comments' permission, apply a patch on https://www.drupal.org/node/2236229

Overrides DataProviderEntity::setPropertyValues

File

modules/restful_example/src/Plugin/resource/comment/DataProviderComment.php, line 23
Contains \Drupal\restful_example\Plugin\resource\comment\DataProviderComment.

Class

DataProviderComment

Namespace

Drupal\restful_example\Plugin\resource\comment

Code

protected function setPropertyValues(\EntityDrupalWrapper $wrapper, $object, $replace = FALSE) {
  $comment = $wrapper
    ->value();
  if (empty($comment->nid) && !empty($object['nid'])) {

    // Comment nid must be set manually, as the nid property setter requires
    // 'administer comments' permission.
    $comment->nid = $object['nid'];
    unset($object['nid']);

    // Make sure we have a bundle name.
    $node = node_load($comment->nid);
    $comment->node_type = 'comment_node_' . $node->type;
  }
  parent::setPropertyValues($wrapper, $object, $replace);
}