-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMultiLanguageNameTrait.php
More file actions
46 lines (38 loc) · 1.2 KB
/
MultiLanguageNameTrait.php
File metadata and controls
46 lines (38 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Core\Repository\Values;
/**
* @internal Meant for internal use by Repository, type hint against API object instead.
*/
trait MultiLanguageNameTrait
{
/**
* Holds the collection of names with languageCode keys.
*
* @var string[]
*/
protected array $names = [];
public function getNames(): array
{
return $this->names;
}
public function getName(?string $languageCode = null): ?string
{
if (!empty($languageCode)) {
return $this->names[$languageCode] ?? null;
}
foreach ($this->prioritizedLanguages as $prioritizedLanguageCode) {
if (isset($this->names[$prioritizedLanguageCode])) {
return $this->names[$prioritizedLanguageCode];
}
}
if (isset($this->mainLanguageCode, $this->names[$this->mainLanguageCode])) {
return $this->names[$this->mainLanguageCode];
}
return $this->names[array_key_first($this->names)] ?? null;
}
}