‪TYPO3CMS  ‪main
OnFieldChangeTrait.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
23 trait OnFieldChangeTrait
24 {
29  protected function getOnFieldChangeItems(array $items): array
30  {
31  if (empty($items)) {
32  return [];
33  }
34  return array_map(
35  static function (OnFieldChangeInterface $item): array {
36  return $item->toArray();
37  },
38  // omitting array keys
39  array_values($items)
40  );
41  }
42 
48  protected function getOnFieldChangeAttrs(string $event, array $items): array
49  {
50  if (empty($items)) {
51  return [];
52  }
53  $onFieldChangeItems = $this->getOnFieldChangeItems($items);
54  return [
55  'data-formengine-field-change-event' => $event,
56  'data-formengine-field-change-items' => GeneralUtility::jsonEncodeForHtmlAttribute($onFieldChangeItems, false),
57  ];
58  }
59 
65  protected function forwardOnFieldChangeQueryParams(array $items): array
66  {
67  $func = $this->getOnFieldChangeItems($items);
68  $hashService = GeneralUtility::makeInstance(HashService::class);
69  return [
70  'fieldChangeFunc' => $func,
71  'fieldChangeFuncHash' => $hashService->hmac(serialize($func), 'backend-link-browser'),
72  ];
73  }
74 }
‪TYPO3\CMS\Backend\Form\Behavior
Definition: OnFieldChangeInterface.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Crypto\HashService
Definition: HashService.php:27