ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TitleAndDescription.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ILIAS\Refinery\Factory as Refinery;
28
33{
34 private const TITLE_LABEL = 'title';
35 private const DESCRIPTION_LABEL = 'description';
36 private const GROUP_LABEL = 'title_and_description';
37
38 public function __construct(
39 private string $title = '',
40 private string $long_description = '',
41 private ?ObjectTypeSpecificPropertyModifications $object_type_specific_property_modifications = null
42 ) {
43 }
44
45 public function getTitle(): string
46 {
47 if ($this->object_type_specific_property_modifications !== null) {
48 return $this->object_type_specific_property_modifications->modifyTitle($this->title);
49 }
50
51 return $this->title;
52 }
53
54 public function withTitle(string $title): self
55 {
56 $clone = clone $this;
57 $clone->title = $title;
58 return $clone;
59 }
60
61 public function getDescription(): string
62 {
63 return mb_substr($this->getLongDescription(), 0, \ilObject::DESC_LENGTH);
64 }
65
66 public function withDescription(string $description): self
67 {
68 $clone = clone $this;
69 $clone->long_description = $description;
70 return $clone;
71 }
72
73 public function getLongDescription(): ?string
74 {
75 if ($this->object_type_specific_property_modifications !== null) {
76 return $this->object_type_specific_property_modifications->modifyDescription($this->long_description);
77 }
78 return $this->long_description;
79 }
80
81 public function toForm(
82 \ilLanguage $language,
83 FieldFactory $field_factory,
85 ): FormInput {
86 $trafo = $refinery->custom()->transformation(
87 function ($vs): Property {
88 list($title, $long_description) = $vs;
89 return new self(
90 $title,
91 $long_description
92 );
93 }
94 );
95
96 $title_input = $field_factory->text($language->txt(self::TITLE_LABEL))
97 ->withoutStripTags()
98 ->withMaxLength(\ilObject::TITLE_LENGTH)
99 ->withRequired(true)
100 ->withValue($this->title);
101 $description_input = $field_factory->textarea($language->txt(self::DESCRIPTION_LABEL))
102 ->withoutStripTags()
103 ->withMaxLimit(\ilObject::LONG_DESC_LENGTH)
104 ->withValue($this->long_description);
105 return $field_factory->group([$title_input, $description_input], self::GROUP_LABEL)
106 ->withAdditionalTransformation($trafo);
107 }
108}
Builds data types.
Definition: Factory.php:36
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery)
__construct(private string $title='', private string $long_description='', private ?ObjectTypeSpecificPropertyModifications $object_type_specific_property_modifications=null)
language handling
const TITLE_LENGTH
const LONG_DESC_LENGTH
const DESC_LENGTH
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...