ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Mode.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Data\Factory as DataFactory;
27use ILIAS\Refinery\Factory as Refinery;
30
31class Mode extends ViewControlInput implements VCInterface\Mode
32{
33 public function __construct(
34 DataFactory $data_factory,
36 protected array $options
37 ) {
38 $keys = array_keys($options);
39 $this->checkArgListElements('options', $keys, 'string');
40 $this->checkArgListElements('options', $options, 'string');
41 if (count($options) < 2) {
42 throw new \InvalidArgumentException('ModeViewControls must contain more than one option.');
43 }
45 $refinery->custom()->transformation(
46 static fn($v) => $v ?? array_key_first($options)
47 )
48 );
49 parent::__construct($data_factory, $refinery);
50 }
51
52 protected function isClientSideValueOk($value): bool
53 {
54 return is_null($value) || is_string($value);
55 }
56
57 public function getOptions(): array
58 {
59 return $this->options;
60 }
61
62 public function withAriaLabel(string $label): self
63 {
64 $clone = clone $this;
65 $clone->label = $label;
66 return $clone;
67 }
68}
Builds data types.
Definition: Factory.php:36
setAdditionalTransformation(Transformation $trafo)
Apply a transformation to the current or future content.
Definition: Input.php:158
__construct(DataFactory $data_factory, Refinery $refinery, protected array $options)
Definition: Mode.php:33
isClientSideValueOk($value)
Check if the value is good to be displayed client side.
Definition: Mode.php:52
A transformation is a function from one datatype to another.
This describes commonalities between all inputs.
Definition: Input.php:47
This describes a Mode View Control.
Definition: Mode.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21