summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-12-04 11:38:10 (GMT)
committerAlex Pott2014-12-04 11:39:51 (GMT)
commitcf00c8c140a4a5a0f4521d78e8ac30d666a72182 (patch)
tree3c3b6b5732805e739976f5a376dbd1cdf7430ea7
parent4ecc4ead39c67a3ea63bec6ce3510610cc4fde33 (diff)
Issue #2349805 by balagan, clemens.tolboom, Cyberwolf: Rest classes should use StringTranslationTrait instead of t() function when possible
-rw-r--r--core/modules/rest/src/Plugin/ResourceBase.php2
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php23
-rw-r--r--core/modules/rest/src/Plugin/views/row/DataFieldRow.php2
3 files changed, 14 insertions, 13 deletions
diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php
index 0cf3281..ef16078 100644
--- a/core/modules/rest/src/Plugin/ResourceBase.php
+++ b/core/modules/rest/src/Plugin/ResourceBase.php
@@ -87,7 +87,7 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin
foreach ($this->availableMethods() as $method) {
$lowered_method = strtolower($method);
$permissions["restful $lowered_method $this->pluginId"] = array(
- 'title' => t('Access @method on %label resource', array('@method' => $method, '%label' => $definition['label'])),
+ 'title' => $this->t('Access @method on %label resource', array('@method' => $method, '%label' => $definition['label'])),
);
}
return $permissions;
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);
}
}
diff --git a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php
index 980f80c1..71502f5 100644
--- a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php
+++ b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php
@@ -79,7 +79,7 @@ class DataFieldRow extends RowPluginBase {
$form['field_options'] = array(
'#type' => 'table',
- '#header' => array(t('Field'), $this->t('Alias'), $this->t('Raw output')),
+ '#header' => array($this->t('Field'), $this->t('Alias'), $this->t('Raw output')),
'#empty' => $this->t('You have no fields. Add some to your view.'),
'#tree' => TRUE,
);