From 73b4641d144d0f13c4bc817abba5c0d8d9cf965b Mon Sep 17 00:00:00 2001 From: Alex Weber Date: Tue, 16 Dec 2014 11:47:42 -0200 Subject: [PATCH 1/5] remove duplicate code in RestfulEntityBaseMultipleBundles RestfulBase will instantiate those 2 in the exact same way so we can just pass the params along --- plugins/restful/RestfulEntityBaseMultipleBundles.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/restful/RestfulEntityBaseMultipleBundles.php b/plugins/restful/RestfulEntityBaseMultipleBundles.php index 547d5203..29b99fd8 100644 --- a/plugins/restful/RestfulEntityBaseMultipleBundles.php +++ b/plugins/restful/RestfulEntityBaseMultipleBundles.php @@ -27,14 +27,15 @@ public static function controllersInfo() { ); } + /** + * Overrides \RestfulBase::__construct(). + */ public function __construct(array $plugin, \RestfulAuthenticationManager $auth_manager = NULL, \DrupalCacheInterface $cache_controller = NULL) { - parent::__construct($plugin); + parent::__construct($plugin, $auth_manager, $cache_controller); if (!empty($plugin['bundles'])) { $this->bundles = $plugin['bundles']; } - $this->authenticationManager = $auth_manager ? $auth_manager : new \RestfulAuthenticationManager(); - $this->cacheController = $cache_controller ? $cache_controller : $this->newCacheObject(); } /** From b5e33d0f1ed31832211251c388b90e53b3c0b0e3 Mon Sep 17 00:00:00 2001 From: Alex Weber Date: Tue, 16 Dec 2014 11:48:31 -0200 Subject: [PATCH 2/5] add a new language property in RestfulEntityBase --- plugins/restful/RestfulEntityBase.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/restful/RestfulEntityBase.php b/plugins/restful/RestfulEntityBase.php index daf3219d..215aa6df 100644 --- a/plugins/restful/RestfulEntityBase.php +++ b/plugins/restful/RestfulEntityBase.php @@ -71,6 +71,13 @@ abstract class RestfulEntityBase extends \RestfulDataProviderEFQ implements \Res */ protected $publicFields = array(); + /** + * The language of the data exposed to the API. + * + * @var string + */ + protected $language; + /** * Overrides \RestfulDataProviderEFQ::controllersInfo(). */ From 30000db27bb77b655bd8062a3711c01bf126d836 Mon Sep 17 00:00:00 2001 From: Alex Weber Date: Tue, 16 Dec 2014 11:48:53 -0200 Subject: [PATCH 3/5] use new language property in RestfulEntityBase::viewEntity() instead of global $language if possible --- plugins/restful/RestfulEntityBase.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/restful/RestfulEntityBase.php b/plugins/restful/RestfulEntityBase.php index 215aa6df..18af64cb 100644 --- a/plugins/restful/RestfulEntityBase.php +++ b/plugins/restful/RestfulEntityBase.php @@ -275,7 +275,6 @@ protected function getQueryResultForAutocomplete() { * {@inheritdoc} */ public function viewEntity($entity_id) { - global $language; $request = $this->getRequest(); $cached_data = $this->getRenderedCache(array( @@ -290,8 +289,18 @@ public function viewEntity($entity_id) { return; } + // Figure out language. + if (!empty($this->language)) { + $wrapper_language = $this->language; + + } + else { + global $language; + $wrapper_language = $language->language; + } + $wrapper = entity_metadata_wrapper($this->entityType, $entity_id); - $wrapper->language($language->language); + $wrapper->language($wrapper_language); $values = array(); $limit_fields = !empty($request['fields']) ? explode(',', $request['fields']) : array(); From e11aa5d8c63e30312caa1ae931db3c9434b321d2 Mon Sep 17 00:00:00 2001 From: Alex Weber Date: Tue, 16 Dec 2014 11:49:18 -0200 Subject: [PATCH 4/5] tentatively inject language as a string in RestfulEntityBase constructor --- plugins/restful/RestfulEntityBase.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/restful/RestfulEntityBase.php b/plugins/restful/RestfulEntityBase.php index 18af64cb..0b1a0eb4 100644 --- a/plugins/restful/RestfulEntityBase.php +++ b/plugins/restful/RestfulEntityBase.php @@ -78,6 +78,17 @@ abstract class RestfulEntityBase extends \RestfulDataProviderEFQ implements \Res */ protected $language; + /** + * Overrides \RestfulDataProviderEFQ::__construct(). + * + * @param string $language + * (optional) The entity language. + */ + public function __construct(array $plugin, \RestfulAuthenticationManager $auth_manager = NULL, \DrupalCacheInterface $cache_controller = NULL, $language = NULL) { + parent::__construct($plugin, $auth_manager, $cache_controller); + $this->language = $language; + } + /** * Overrides \RestfulDataProviderEFQ::controllersInfo(). */ From 1468578099ab6ebad0d366347bfcfa8e9d98663e Mon Sep 17 00:00:00 2001 From: Alex Weber Date: Tue, 16 Dec 2014 11:52:02 -0200 Subject: [PATCH 5/5] update RestfulEntityBaseMultipleBundles constructor with injected language --- plugins/restful/RestfulEntityBaseMultipleBundles.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/restful/RestfulEntityBaseMultipleBundles.php b/plugins/restful/RestfulEntityBaseMultipleBundles.php index 29b99fd8..917b6696 100644 --- a/plugins/restful/RestfulEntityBaseMultipleBundles.php +++ b/plugins/restful/RestfulEntityBaseMultipleBundles.php @@ -30,8 +30,8 @@ public static function controllersInfo() { /** * Overrides \RestfulBase::__construct(). */ - public function __construct(array $plugin, \RestfulAuthenticationManager $auth_manager = NULL, \DrupalCacheInterface $cache_controller = NULL) { - parent::__construct($plugin, $auth_manager, $cache_controller); + public function __construct(array $plugin, \RestfulAuthenticationManager $auth_manager = NULL, \DrupalCacheInterface $cache_controller = NULL, $language = NULL) { + parent::__construct($plugin, $auth_manager, $cache_controller, $language); if (!empty($plugin['bundles'])) { $this->bundles = $plugin['bundles'];