ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
Form.php
Go to the documentation of this file.
1<?php
2
4
8
12class Form
13{
14 private \ilLanguage $language;
16 private \ILIAS\Refinery\Factory $refinery;
17
18 public function __construct(
19 private Settings $settings,
20 private bool $write_access
21 ) {
22 global $DIC;
23 $this->language = $DIC->language();
24 $this->field_factory = $DIC->ui()->factory()->input()->field();
25 $this->refinery = $DIC->refinery();
26 }
27
28 public function asFormSection(): Section
29 {
30 return $this->field_factory->section(
31 [$this->asFormGroup()],
32 $this->language->txt('preview')
33 );
34 }
35
36 public function asFormGroup(): Group
37 {
38 $possible = $this->settings->isPreviewPossible();
39
40 $activated = $this->field_factory
41 ->checkbox(
42 $this->language->txt('enable_preview'),
43 $this->language->txt('enable_preview_info')
44 )
45 ->withDisabled(!$this->write_access || !$possible)
46 ->withValue($this->settings->isPreviewEnabled())
47 ->withAdditionalTransformation(
48 $this->refinery->custom()->transformation(function (bool $v): void {
49 $this->settings->setPreviewEnabled($v);
50 })
51 );
52
53 $image_size = $this->field_factory
54 ->numeric(
55 $this->language->txt('preview_image_size'),
56 $this->language->txt('preview_image_size_info')
57 )
58 ->withDisabled(!$this->write_access || !$possible)
59 ->withRequired(true)
60 ->withValue($this->settings->getImageSize())
61 ->withAdditionalTransformation(
62 $this->refinery->custom()->transformation(function (int $v): void {
63 $this->settings->setImageSize($v);
64 })
65 );
66
67 $persisting = $this->field_factory
68 ->checkbox(
69 $this->language->txt('preview_persisting'),
70 $this->language->txt('preview_persisting_info')
71 )
72 ->withDisabled(!$this->write_access || !$possible)
73 ->withValue($this->settings->isPersisting())
74 ->withAdditionalTransformation(
75 $this->refinery->custom()->transformation(function (bool $v): void {
76 $this->settings->setPersisting($v);
77 })
78 );
79
80 $max_previews = $this->field_factory
81 ->numeric(
82 $this->language->txt('max_previews_per_object'),
83 $this->language->txt('max_previews_per_object_info')
84 )
85 ->withDisabled(!$this->write_access || !$possible)
86 ->withValue($this->settings->getMaximumPreviews())
87 ->withAdditionalTransformation(
88 $this->refinery->custom()->transformation(function (int $v): void {
89 $this->settings->setMaximumPreviews($v);
90 })
91 );
92
93 $tile_previews = $this->field_factory
94 ->checkbox(
95 $this->language->txt('previews_for_tiles'),
96 $this->language->txt('previews_for_tiles_info')
97 )
98 ->withDisabled(!$this->write_access || !$possible)
99 ->withValue($this->settings->hasTilePreviews())
100 ->withAdditionalTransformation(
101 $this->refinery->custom()->transformation(function (bool $v): void {
102 $this->settings->setTilePreviews($v);
103 })
104 );
105
106 return $this->field_factory->group(
107 [
108 $activated,
109 $image_size,
110 $max_previews,
111 $persisting,
112 $tile_previews
113 ]
114 );
115 }
116}
__construct(private Settings $settings, private bool $write_access)
Definition: Form.php:18
ILIAS Refinery Factory $refinery
Definition: Form.php:16
This is what a factory for input fields looks like.
Definition: Factory.php:31
Describes the monoid operation of grouping form inputs.
Definition: Group.php:32
This describes section inputs.
Definition: Section.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Form.php:3
global $DIC
Definition: shib_login.php:26