ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Language.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Language\Language as SystemLanguage;
27use ILIAS\Refinery\Factory as Refinery;
28
30{
31 public function __construct(
32 private readonly string $language_code,
33 private string $title,
34 private string $description,
35 private bool $default = false,
36 private bool $base = false
37 ) {
38 }
39
40 public function getLanguageCode(): string
41 {
42 return $this->language_code;
43 }
44
45 public function getTitle(): string
46 {
47 return $this->title;
48 }
49
50 public function withTitle(string $title): self
51 {
52 $clone = clone $this;
53 $clone->title = $title;
54 return $clone;
55 }
56
57 public function getDescription(): string
58 {
59 return $this->description;
60 }
61
62 public function withDescription(string $description): self
63 {
64 $clone = clone $this;
65 $clone->description = $description;
66 return $clone;
67 }
68
69 public function isDefault(): bool
70 {
71 return $this->default;
72 }
73
74 public function withDefault(bool $default): self
75 {
76 $clone = clone $this;
77 $clone->default = $default;
78 return $clone;
79 }
80
81 public function isBase(): bool
82 {
83 return $this->base;
84 }
85
86 public function withBase(bool $base): self
87 {
88 $clone = clone $this;
89 $clone->base = $base;
90 return $clone;
91 }
92
93 public function toForm(
94 \ilLanguage $language,
95 FieldFactory $field_factory,
97 ): array {
98 return [
99 $field_factory->group([
100 'language' => $field_factory->hidden()->withValue($this->language_code),
101 'title' => $field_factory->text($language->txt('title'))
102 ->withRequired(true)
103 ->withValue($this->title),
104 'description' => $field_factory->textarea($language->txt('description'))
105 ->withValue($this->description),
106 'default' => $field_factory->hidden()->withValue($this->isDefault()),
107 'base' => $field_factory->hidden()->withValue($this->isBase()),
109 $refinery->custom()->transformation(
110 static fn(array $vs): self => new self(
111 $vs['language'],
112 $vs['title'],
113 $vs['description'],
114 $vs['default'] === '1',
115 $vs['base'] === '1'
116 )
117 )
118 )
119 ];
120 }
121
122 public function toRow(
123 DataRowBuilder $row_builder,
124 SystemLanguage $lng
125 ): DataRow {
126 return $row_builder->buildDataRow(
127 $this->language_code,
128 [
129 'language' => $this->getTranslatedLanguageName($lng, $this->language_code),
130 'base' => $this->isBase(),
131 'default' => $this->isDefault(),
132 'title' => $this->getTitle(),
133 'description' => $this->getDescription()
134 ]
135 )->withDisabledAction(TranslationsTable::ACTION_DELETE, $this->isBase() || $this->isDefault())
136 ->withDisabledAction(TranslationsTable::ACTION_MAKE_DEFAULT, $this->isDefault());
137 }
138
140 SystemLanguage $lng,
141 string $language_code
142 ): string {
143 return $lng->txt("meta_l_{$language_code}");
144 }
145}
Builds data types.
Definition: Factory.php:36
getTranslatedLanguageName(SystemLanguage $lng, string $language_code)
Definition: Language.php:139
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery)
Definition: Language.php:93
__construct(private readonly string $language_code, private string $title, private string $description, private bool $default=false, private bool $base=false)
Definition: Language.php:31
toRow(DataRowBuilder $row_builder, SystemLanguage $lng)
Definition: Language.php:122
return true
language handling
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is what a factory for input fields looks like.
Definition: Factory.php:31
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $lng
Definition: privfeed.php:31