You are here

public function RestfulEntityBase::createEntity in RESTful 7

Create a new entity.

Return value

array Array with the output of the new entity, passed to RestfulEntityInterface::viewEntity().

Throws

RestfulForbiddenException

Overrides RestfulDataProviderEFQ::createEntity

1 method overrides RestfulEntityBase::createEntity()
RestfulFilesUpload::createEntity in plugins/restful/RestfulFilesUpload.php
Create and save files.

File

plugins/restful/RestfulEntityBase.php, line 630
Contains RestfulEntityBase.

Class

RestfulEntityBase
An abstract implementation of RestfulEntityInterface.

Code

public function createEntity() {
  $entity_info = $this
    ->getEntityInfo();
  $bundle_key = $entity_info['entity keys']['bundle'];
  $values = $bundle_key ? array(
    $bundle_key => $this->bundle,
  ) : array();
  $entity = entity_create($this->entityType, $values);
  if ($this
    ->checkEntityAccess('create', $this->entityType, $entity) === FALSE) {

    // User does not have access to create entity.
    $params = array(
      '@resource' => $this
        ->getPluginKey('label'),
    );
    throw new RestfulForbiddenException(format_string('You do not have access to create a new @resource resource.', $params));
  }
  $wrapper = entity_metadata_wrapper($this->entityType, $entity);
  $this
    ->setPropertyValues($wrapper);
  return array(
    $this
      ->viewEntity($wrapper
      ->getIdentifier()),
  );
}