ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
DatetimeFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
33 {
34  protected Refinery $refinery;
36 
37  public function __construct(
41  Refinery $refinery,
42  DataHelperInterface $data_helper
43  ) {
44  parent::__construct($ui_factory, $presenter, $constraint_dictionary);
45  $this->refinery = $refinery;
46  $this->data_helper = $data_helper;
47  }
48 
49  protected function rawInput(
50  ElementInterface $element,
51  ElementInterface $context_element,
52  string $condition_value = ''
53  ): FormInput {
54  $dh = $this->data_helper;
55  return $this->ui_factory
56  ->dateTime('placeholder')
57  ->withFormat($this->presenter->utilities()->getUserDateFormat())
59  $this->refinery->custom()->transformation(
60  function ($v) use ($dh) {
61  return isset($v) ? $dh->datetimeFromObject($v) : '';
62  }
63  )
64  );
65  }
66 
67  protected function dataValueForInput(DataInterface $data): string
68  {
69  $date = $this->data_helper->datetimeToObject($data->value());
70  return $this->presenter->utilities()->getUserDateFormat()->applyTo($date);
71  }
72 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
rawInput(ElementInterface $element, ElementInterface $context_element, string $condition_value='')
__construct(VocabulariesInterface $vocabularies)
__construct(UIFactory $ui_factory, PresenterInterface $presenter, ConstraintDictionary $constraint_dictionary, Refinery $refinery, DataHelperInterface $data_helper)
This describes inputs that can be used in forms.
Definition: FormInput.php:31
value()
Value of the data, in a format according to its type.