‪TYPO3CMS  10.4
InsertClipboard.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 
24 
30 {
36  public function ‪render(): array
37  {
38  $languageService = $this->‪getLanguageService();
39 
40  $parameterArray = $this->data['parameterArray'];
41  $elementName = $parameterArray['itemFormElName'];
42  $config = $parameterArray['fieldConf']['config'];
43  $internalType = (string)$config['internal_type'];
44  $clipboardElements = $config['clipboardElements'];
45 
46  if ((isset($config['readOnly']) && $config['readOnly'])
47  || empty($clipboardElements)
48  ) {
49  return [];
50  }
51 
52  $title = '';
53  $dataAttributes = [
54  'element' => $elementName,
55  'clipboardItems' => [],
56  ];
57  if ($internalType === 'db') {
58  $title = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_db'), count($clipboardElements));
59  foreach ($clipboardElements as $clipboardElement) {
60  $dataAttributes['clipboardItems'][] = [
61  'title' => $clipboardElement['title'],
62  'value' => $clipboardElement['value'],
63  ];
64  }
65  }
66 
67  $id = ‪StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
68 
69  return [
70  'iconIdentifier' => 'actions-document-paste-into',
71  'title' => $title,
72  'linkAttributes' => [
73  'id' => htmlspecialchars($id),
74  'data-element' => $dataAttributes['element'],
75  'data-clipboard-items' => json_encode($dataAttributes['clipboardItems']),
76  ],
77  'requireJsModules' => [
78  ['TYPO3/CMS/Backend/FormEngine/FieldControl/InsertClipboard' => 'function(FieldControl) {new FieldControl(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
79  ],
80  ];
81  }
82 
87  {
88  return ‪$GLOBALS['LANG'];
89  }
90 }
‪TYPO3\CMS\Backend\Form\FieldControl
Definition: AddRecord.php:18
‪TYPO3\CMS\Backend\Form\FieldControl\InsertClipboard
Definition: InsertClipboard.php:30
‪TYPO3\CMS\Backend\Form\FieldControl\InsertClipboard\render
‪array render()
Definition: InsertClipboard.php:36
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Backend\Form\FieldControl\InsertClipboard\getLanguageService
‪LanguageService getLanguageService()
Definition: InsertClipboard.php:86