ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
GroupForm.php
Go to the documentation of this file.
1<?php
2
20
23use Psr\Http\Message\RequestInterface;
24use ILIAS\GlobalScreen\GUI\I18n\Translator;
25
27{
28 private readonly Factory $ui_factory;
29 private readonly \ILIAS\Refinery\Factory $refinery;
30
31 public function __construct(
32 private readonly GroupsRepository $repository,
33 private readonly Translator $translator,
34 private ?Group $group = null,
35 ) {
36 global $DIC;
37 $this->ui_factory = $DIC->ui()->factory();
38 $this->refinery = $DIC->refinery();
39 $this->group ??= $this->repository->blank();
40 }
41
42 protected function getInputs(): array
43 {
44 $ff = $this->ui_factory->input()->field();
45
46 return [
47 'title' => $ff
48 ->text($this->translator->translate('title', 'group'))
49 ->withValue($this->group->getTitle())
50 ->withAdditionalTransformation(
51 $this->refinery->custom()->transformation(function (string $value): string {
52 $this->group = $this->group->withTitle($value);
53 return $value;
54 })
55 )
56 ->withRequired(true)
57 ->withMaxLength(255),
58 'active' => $ff
59 ->checkbox($this->translator->translate('active', 'group'))
60 ->withValue($this->group->isActive())
61 ->withAdditionalTransformation(
62 $this->refinery->custom()->transformation(function (bool $value): bool {
63 $this->group = $this->group->withActive($value);
64 return $value;
65 })
66 )
67 ,
68 ];
69 }
70
71 public function get(string $target): Standard
72 {
73 return $this->ui_factory
74 ->input()
75 ->container()
76 ->form()
77 ->standard($target, $this->getInputs())
79 $this->refinery->custom()->transformation(fn(array $value): ?Group => $this->group)
80 );
81 }
82
83 public function store(RequestInterface $request, string $target): bool
84 {
85 $form = $this->get($target)->withRequest($request);
86 $data = $form->getData();
87 if ($data !== null) {
88 $this->repository->store($this->group);
89 return true;
90 }
91 return false;
92 }
93
94}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
readonly ILIAS Refinery Factory $refinery
Definition: GroupForm.php:29
__construct(private readonly GroupsRepository $repository, private readonly Translator $translator, private ?Group $group=null,)
Definition: GroupForm.php:31
store(RequestInterface $request, string $target)
Definition: GroupForm.php:83
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...
Definition: Group.php:19
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
global $DIC
Definition: shib_login.php:26