ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Form.php
Go to the documentation of this file.
1 <?php
2 
20 
23 
27 class Form
28 {
29  private \ilLanguage $language;
30  private \ILIAS\UI\Component\Input\Field\Factory $field_factory;
31  private \ILIAS\Refinery\Factory $refinery;
32 
33  public function __construct(private Settings $settings)
34  {
35  global $DIC;
36  $this->language = $DIC->language();
37  $this->field_factory = $DIC->ui()->factory()->input()->field();
38  $this->refinery = $DIC->refinery();
39  }
40 
41  public function asFormSection(): Section
42  {
43  return $this->field_factory->section(
44  [$this->asFormGroup()],
45  $this->language->txt('preview')
46  );
47  }
48 
49  public function asFormGroup(): Group
50  {
51  $possible = $this->settings->isPreviewPossible();
52 
53  $activated = $this->field_factory
54  ->checkbox(
55  $this->language->txt('enable_preview'),
56  $this->language->txt('enable_preview_info')
57  )
58  ->withDisabled(!$possible)
59  ->withValue($this->settings->isPreviewEnabled())
61  $this->refinery->custom()->transformation(function ($v): void {
62  $this->settings->setPreviewEnabled($v);
63  })
64  );
65 
66  $image_size = $this->field_factory
67  ->numeric(
68  $this->language->txt('preview_image_size'),
69  $this->language->txt('preview_image_size_info')
70  )
71  ->withDisabled(!$possible)
72  ->withRequired(true)
73  ->withValue($this->settings->getImageSize())
75  $this->refinery->custom()->transformation(function ($v): void {
76  $this->settings->setImageSize($v);
77  })
78  );
79 
80  $persisting = $this->field_factory
81  ->checkbox(
82  $this->language->txt('preview_persisting'),
83  $this->language->txt('preview_persisting_info')
84  )
85  ->withDisabled(!$possible)
86  ->withValue($this->settings->isPersisting())
88  $this->refinery->custom()->transformation(function ($v): void {
89  $this->settings->setPersisting($v);
90  })
91  );
92 
93  $max_previews = $this->field_factory
94  ->numeric(
95  $this->language->txt('max_previews_per_object'),
96  $this->language->txt('max_previews_per_object_info')
97  )
98  ->withDisabled(!$possible)
99  ->withValue($this->settings->getMaximumPreviews())
101  $this->refinery->custom()->transformation(function ($v): void {
102  $this->settings->setMaximumPreviews($v);
103  })
104  );
105 
106  $tile_previews = $this->field_factory
107  ->checkbox(
108  $this->language->txt('previews_for_tiles'),
109  $this->language->txt('previews_for_tiles_info')
110  )
111  ->withDisabled(!$possible)
112  ->withValue($this->settings->hasTilePreviews())
114  $this->refinery->custom()->transformation(function ($v): void {
115  $this->settings->setTilePreviews($v);
116  })
117  );
118 
119  return $this->field_factory->group(
120  [
121  $activated,
122  $image_size,
123  $max_previews,
124  $persisting,
125  $tile_previews
126  ]
127  );
128  }
129 }
ILIAS UI Component Input Field Factory $field_factory
Definition: Form.php:30
This describes section inputs.
Definition: Section.php:28
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
__construct(private Settings $settings)
Definition: Form.php:33
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Form.php:19
ILIAS Refinery Factory $refinery
Definition: Form.php:31