TYPO3 CMS  TYPO3_8-7
ResetSelection.php
Go to the documentation of this file.
1 <?php
2 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 
20 
26 {
32  public function render()
33  {
34  $parameterArray = $this->data['parameterArray'];
35  $itemName = $parameterArray['itemFormElName'];
36 
37  $selectItems = $parameterArray['fieldConf']['config']['items'];
38  $itemArray = array_flip($parameterArray['itemFormElValue']);
39  $initiallySelectedIndices = [];
40  foreach ($selectItems as $i => $item) {
41  $value = $item[1];
42  // Selected or not by default
43  if (isset($itemArray[$value])) {
44  $initiallySelectedIndices[] = $i;
45  }
46  }
47 
48  $resetCode = [
49  'document.editform[' . GeneralUtility::quoteJSvalue($itemName . '[]') . '].selectedIndex=-1;'
50  ];
51  foreach ($initiallySelectedIndices as $index) {
52  $resetCode[] = 'document.editform[' . GeneralUtility::quoteJSvalue($itemName . '[]') . '].options[' . $index . '].selected=1;';
53  }
54  $resetCode[] = 'return false;';
55 
56  return [
57  'iconIdentifier' => 'actions-edit-undo',
58  'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.revertSelection',
59  'linkAttributes' => [
60  'onClick' => implode('', $resetCode),
61  ],
62  ];
63  }
64 }