‪TYPO3CMS  ‪main
ResetSelection.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 
23 
29 {
35  public function ‪render(): array
36  {
37  $parameterArray = $this->data['parameterArray'];
38  $selectItems = $parameterArray['fieldConf']['config']['items'];
39  if (($parameterArray['fieldConf']['config']['readOnly'] ?? false) || empty($selectItems)) {
40  // Early return if the field is readOnly or no items exist
41  return [];
42  }
43  $itemName = $parameterArray['itemFormElName'];
44  $itemArray = array_flip($parameterArray['itemFormElValue']);
45  $initiallySelectedIndices = [];
46  foreach ($selectItems as $i => $item) {
47  $value = $item['value'];
48  // Selected or not by default
49  if (isset($itemArray[$value])) {
50  $initiallySelectedIndices[] = $i;
51  }
52  }
53 
54  $id = ‪StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
55 
56  return [
57  'iconIdentifier' => 'actions-edit-undo',
58  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.revertSelection',
59  'linkAttributes' => [
60  'id' => $id,
61  'data-item-name' => $itemName,
62  'data-selected-indices' => json_encode($initiallySelectedIndices),
63  ],
64  'javaScriptModules' => [
65  ‪JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/reset-selection.js')->instance('#' . $id),
66  ],
67  ];
68  }
69 }
‪TYPO3\CMS\Backend\Form\FieldControl
Definition: AddRecord.php:18
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Backend\Form\FieldControl\ResetSelection
Definition: ResetSelection.php:29
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Backend\Form\FieldControl\ResetSelection\render
‪array render()
Definition: ResetSelection.php:35
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57