summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
diff options
context:
space:
mode:
authorAlex Pott2014-12-04 11:38:10 +0000
committerAlex Pott2014-12-04 11:39:51 +0000
commitcf00c8c140a4a5a0f4521d78e8ac30d666a72182 (patch)
tree3c3b6b5732805e739976f5a376dbd1cdf7430ea7 /core/modules/rest/src/Plugin/rest/resource/EntityResource.php
parent4ecc4ead39c67a3ea63bec6ce3510610cc4fde33 (diff)
Issue #2349805 by balagan, clemens.tolboom, Cyberwolf: Rest classes should use StringTranslationTrait instead of t() function when possible
Diffstat (limited to 'core/modules/rest/src/Plugin/rest/resource/EntityResource.php')
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php23
1 files changed, 12 insertions, 11 deletions
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index 7b3e49e..c58ff1a 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
+use Drupal\Component\Utility\String;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -69,7 +70,7 @@ class EntityResource extends ResourceBase {
*/
public function post(EntityInterface $entity = NULL) {
if ($entity == NULL) {
- throw new BadRequestHttpException(t('No entity content received.'));
+ throw new BadRequestHttpException('No entity content received.');
}
if (!$entity->access('create')) {
@@ -79,16 +80,16 @@ class EntityResource extends ResourceBase {
// Verify that the deserialized entity is of the type that we expect to
// prevent security issues.
if ($entity->getEntityTypeId() != $definition['entity_type']) {
- throw new BadRequestHttpException(t('Invalid entity type'));
+ throw new BadRequestHttpException('Invalid entity type');
}
// POSTed entities must not have an ID set, because we always want to create
// new entities here.
if (!$entity->isNew()) {
- throw new BadRequestHttpException(t('Only new entities can be created'));
+ throw new BadRequestHttpException('Only new entities can be created');
}
foreach ($entity as $field_name => $field) {
if (!$field->access('create')) {
- throw new AccessDeniedHttpException(t('Access denied on creating field @field.', array('@field' => $field_name)));
+ throw new AccessDeniedHttpException(String::format('Access denied on creating field ', array('@field' => $field_name)));
}
}
@@ -103,7 +104,7 @@ class EntityResource extends ResourceBase {
return new ResourceResponse(NULL, 201, array('Location' => $url));
}
catch (EntityStorageException $e) {
- throw new HttpException(500, t('Internal Server Error'), $e);
+ throw new HttpException(500, 'Internal Server Error', $e);
}
}
@@ -122,11 +123,11 @@ class EntityResource extends ResourceBase {
*/
public function patch(EntityInterface $original_entity, EntityInterface $entity = NULL) {
if ($entity == NULL) {
- throw new BadRequestHttpException(t('No entity content received.'));
+ throw new BadRequestHttpException('No entity content received.');
}
$definition = $this->getPluginDefinition();
if ($entity->getEntityTypeId() != $definition['entity_type']) {
- throw new BadRequestHttpException(t('Invalid entity type'));
+ throw new BadRequestHttpException('Invalid entity type');
}
if (!$original_entity->access('update')) {
throw new AccessDeniedHttpException();
@@ -143,11 +144,11 @@ class EntityResource extends ResourceBase {
continue;
}
if ($field->isEmpty() && !$original_entity->get($field_name)->access('delete')) {
- throw new AccessDeniedHttpException(t('Access denied on deleting field @field.', array('@field' => $field_name)));
+ throw new AccessDeniedHttpException(String::format('Access denied on deleting field ', array('@field' => $field_name)));
}
$original_entity->set($field_name, $field->getValue());
if (!$original_entity->get($field_name)->access('update')) {
- throw new AccessDeniedHttpException(t('Access denied on updating field @field.', array('@field' => $field_name)));
+ throw new AccessDeniedHttpException(String::format('Access denied on updating field ', array('@field' => $field_name)));
}
}
}
@@ -162,7 +163,7 @@ class EntityResource extends ResourceBase {
return new ResourceResponse(NULL, 204);
}
catch (EntityStorageException $e) {
- throw new HttpException(500, t('Internal Server Error'), $e);
+ throw new HttpException(500, 'Internal Server Error', $e);
}
}
@@ -189,7 +190,7 @@ class EntityResource extends ResourceBase {
return new ResourceResponse(NULL, 204);
}
catch (EntityStorageException $e) {
- throw new HttpException(500, t('Internal Server Error'), $e);
+ throw new HttpException(500, 'Internal Server Error', $e);
}
}