ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Image.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
21
25use ILIAS\Data\Factory as DataFactory;
27use ILIAS\Refinery\Factory as Refinery;
29
33class Image extends File implements C\Input\Field\Image
34{
35 public function __construct(
36 Language $language,
37 DataFactory $data_factory,
38 Factory $field_factory,
42 protected ImagePurpose $image_purpose,
43 string $label,
44 ?FormInput $metadata_input,
45 ?string $byline
46 ) {
48 $language,
49 $data_factory,
50 $field_factory,
54 $label,
55 $this->createMetaDataInput($language, $field_factory, $metadata_input),
56 $byline,
57 );
58
59 $this->accepted_mime_types = ['image/*'];
60 }
61
62 public function getImagePurpose(): ImagePurpose
63 {
64 return $this->image_purpose;
65 }
66
67 protected function createMetaDataInput(
68 Language $language,
69 Factory $field_factory,
70 ?FormInput $metadata_input
71 ): ?FormInput {
72 $image_purpose_input = match ($this->getImagePurpose()) {
73 ImagePurpose::USER_DEFINED => $this->createUserDefinedAltTextField($language, $field_factory),
74 ImagePurpose::INFORMATIVE => $this->createInformativeAltTextField($language, $field_factory),
75 default => null,
76 };
77 if (null === $image_purpose_input && null === $metadata_input) {
78 return null;
79 }
80 if (null === $image_purpose_input && null !== $metadata_input) {
81 return $metadata_input;
82 }
83 if (null !== $image_purpose_input && null === $metadata_input) {
84 return $field_factory->group([$image_purpose_input]);
85 }
86 return $field_factory->group([$image_purpose_input, $metadata_input]);
87 }
88
89 protected function createUserDefinedAltTextField(Language $language, Factory $field_factory): FormInput
90 {
91 return $field_factory->switchableGroup([
92 ImagePurpose::INFORMATIVE->name => $field_factory->group([$field_factory->textarea($language->txt('image_alt_text'))], $language->txt('image_purpose_informative')),
93 ImagePurpose::DECORATIVE->name => $field_factory->group([], $language->txt('image_purpose_decorative'))
94 ], $language->txt('image_purpose_user_defined'))->withRequired(true);
95 }
96
97 protected function createInformativeAltTextField(Language $language, Factory $field_factory): FormInput
98 {
99 return $field_factory->textarea($language->txt('image_alt_text'))->withRequired(true);
100 }
101}
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
ImagePurpose
This enum provides options to categorise the purpose of an image, which will be used to determine whe...
createUserDefinedAltTextField(Language $language, Factory $field_factory)
Definition: Image.php:89
createInformativeAltTextField(Language $language, Factory $field_factory)
Definition: Image.php:97
__construct(Language $language, DataFactory $data_factory, Factory $field_factory, Refinery $refinery, UploadLimitResolver $upload_limit_resolver, C\Input\Field\UploadHandler $handler, protected ImagePurpose $image_purpose, string $label, ?FormInput $metadata_input, ?string $byline)
Definition: Image.php:35
createMetaDataInput(Language $language, Factory $field_factory, ?FormInput $metadata_input)
Definition: Image.php:67
This implements commonalities between inputs.
Definition: Input.php:43
txt(string $a_topic, string $a_default_lang_fallback_mod="")
This describes inputs that can be used in forms.
Definition: FormInput.php:33
__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: Checkbox.php:21
$handler
Definition: oai.php:29