Skip to content

Commit

Permalink
Merge branch 'value-languages' into develop
Browse files Browse the repository at this point in the history
(merge #1633)
  • Loading branch information
zerocrates committed Sep 15, 2020
2 parents 95fdaf0 + 8eff1b9 commit 3688539
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ public function values()
* returns the first matching value.
* - default: (null) Default value if no values match criteria. Returns null
* by default for single result, empty array for all results.
* - lang: (null) Get values of this language only. Returns values of all
* languages by default.
* - lang (array|string): Get values of these languages only. Returns values
* of all languages by default. Use `['']` to get values without language.
* @return ValueRepresentation|ValueRepresentation[]|mixed
*/
public function value($term, array $options = [])
Expand All @@ -329,9 +329,6 @@ public function value($term, array $options = [])
if (!isset($options['default'])) {
$options['default'] = $options['all'] ? [] : null;
}
if (!isset($options['lang'])) {
$options['lang'] = null;
}

if (!$this->getAdapter()->isTerm($term)) {
return $options['default'];
Expand All @@ -349,15 +346,21 @@ public function value($term, array $options = [])
$types = [$options['type']];
}

if (empty($options['lang'])) {
$langs = false;
} elseif (is_array($options['lang'])) {
$langs = $options['lang'];
} else {
$langs = [$options['lang']];
}

// Match only the representations that fit all the criteria.
$matchingValues = [];
foreach ($this->values()[$term]['values'] as $value) {
if ($types && !in_array($value->type(), $types)) {
continue;
}
if (!is_null($options['lang'])
&& $value->lang() !== $options['lang']
) {
if ($langs && !in_array($value->lang(), $langs)) {
continue;
}
$matchingValues[] = $value;
Expand Down

0 comments on commit 3688539

Please sign in to comment.