-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APIv4 - Add generic 'setPreferredLanguage', to all APIs
- Loading branch information
1 parent
64964b6
commit a92d8a5
Showing
4 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* Wrapper to swap in translated text. | ||
*/ | ||
class CRM_Core_BAO_TranslateGetWrapper { | ||
|
||
protected $fields; | ||
protected $translatedLanguage; | ||
|
||
/** | ||
* CRM_Core_BAO_TranslateGetWrapper constructor. | ||
* | ||
* This wrapper replaces values with configured translated values, if any exist. | ||
* | ||
* @param array $translated | ||
*/ | ||
public function __construct($translated) { | ||
$this->fields = $translated['fields']; | ||
$this->translatedLanguage = $translated['language']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function fromApiInput($apiRequest) { | ||
return $apiRequest; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function toApiOutput($apiRequest, $result) { | ||
foreach ($result as &$value) { | ||
if (!isset($value['id'], $this->fields[$value['id']])) { | ||
continue; | ||
} | ||
$toSet = array_intersect_key($this->fields[$value['id']], $value); | ||
$value = array_merge($value, $toSet); | ||
$value['actual_language'] = $this->translatedLanguage; | ||
} | ||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters