ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
EntryForm.php
Go to the documentation of this file.
1<?php
2
20
23use Psr\Http\Message\RequestInterface;
25use ILIAS\GlobalScreen\GUI\I18n\Translator;
26
28{
29 private readonly Factory $ui_factory;
30 private readonly \ILIAS\Refinery\Factory $refinery;
31 private ?Standard $form = null;
32
33 public function __construct(
34 private readonly EntriesRepository $repository,
35 private readonly Translator $translator,
36 private readonly Group $group,
37 private ?Entry $entry = null,
38 ) {
39 global $DIC;
40 $this->ui_factory = $DIC->ui()->factory();
41 $this->refinery = $DIC->refinery();
42 $this->entry ??= $this->repository->blank();
43 }
44
45 protected function getInputs(): array
46 {
47 $ff = $this->ui_factory->input()->field();
48
49 return [
50 'title' => $ff
51 ->text($this->translator->translate('title', 'entry'))
52 ->withValue($this->entry->getTitle())
53 ->withAdditionalTransformation(
54 $this->refinery->custom()->transformation(function (string $value): string {
55 $this->entry = $this->entry->withTitle($value);
56 return $value;
57 })
58 )
59 ->withRequired(true)
60 ->withMaxLength(255),
61 'active' => $ff
62 ->checkbox(
63 $this->translator->translate('active', 'entry'),
64 $this->translator->translate('active_info', 'entry')
65 )
66 ->withValue($this->entry->isActive())
67 ->withAdditionalTransformation(
68 $this->refinery->custom()->transformation(function (bool $value): bool {
69 $this->entry = $this->entry->withActive($value);
70 return $value;
71 })
72 ),
73 'action' => $ff
74 ->url(
75 $this->translator->translate('action', 'entry'),
76 $this->translator->translate('action_info', 'entry')
77 )
78 ->withRequired(true)
79 ->withValue($this->entry->getAction())
80 ->withAdditionalTransformation(
81 $this->refinery->custom()->transformation(function (string $value): string {
82 $this->entry = $this->entry->withAction($value);
83 return $value;
84 })
85 ),
86 'external' => $ff
87 ->checkbox($this->translator->translate('external', 'entry'))
88 ->withValue($this->entry->isExternal())
89 ->withAdditionalTransformation(
90 $this->refinery->custom()->transformation(function (bool $value): bool {
91 $this->entry = $this->entry->withExternal($value);
92 return $value;
93 })
94 ),
95 ];
96 }
97
98 public function get(string $target): Standard
99 {
100 return $this->form ?? $this->ui_factory
101 ->input()
102 ->container()
103 ->form()
104 ->standard($target, $this->getInputs())
106 $this->refinery->custom()->transformation(fn(array $value): ?Entry => $this->entry)
107 );
108 }
109
110 public function store(RequestInterface $request, string $target): bool
111 {
112 $this->form = $this->get($target)->withRequest($request);
113 $data = $this->form->getData();
114 if ($data !== null) {
115 $this->entry = $this->entry->withParent($this->group->getId());
116 $this->repository->store($this->entry);
117 return true;
118 }
119 return false;
120 }
121
122}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
readonly ILIAS Refinery Factory $refinery
Definition: EntryForm.php:30
store(RequestInterface $request, string $target)
Definition: EntryForm.php:110
__construct(private readonly EntriesRepository $repository, private readonly Translator $translator, private readonly Group $group, private ?Entry $entry=null,)
Definition: EntryForm.php:33
This describes a standard form.
Definition: Standard.php:29
This is how the factory for UI elements looks.
Definition: Factory.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
form( $class_path, string $cmd, string $submit_caption="")
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
global $DIC
Definition: shib_login.php:26