‪TYPO3CMS  9.5
InsertClipboard.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 
23 
29 {
35  public function ‪render(): array
36  {
37  $languageService = $this->‪getLanguageService();
38 
39  $parameterArray = $this->data['parameterArray'];
40  $elementName = $parameterArray['itemFormElName'];
41  $config = $parameterArray['fieldConf']['config'];
42  $internalType = (string)$config['internal_type'];
43  $clipboardElements = $config['clipboardElements'];
44 
45  if ((isset($config['readOnly']) && $config['readOnly'])
46  || empty($clipboardElements)
47  ) {
48  return [];
49  }
50 
51  $title = '';
52  $dataAttributes = [
53  'element' => $elementName,
54  'clipboardItems' => [],
55  ];
56  if ($internalType === 'file_reference' || $internalType === 'file') {
57  // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0. Deprecation logged by TcaMigration class.
58  $title = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_file'), count($clipboardElements));
59  foreach ($clipboardElements as $clipboardElement) {
60  $dataAttributes['clipboardItems'][] = [
61  'title' => rawurlencode(‪PathUtility::basename($clipboardElement['title'])),
62  'value' => $clipboardElement['value'],
63  ];
64  }
65  } elseif ($internalType === 'db') {
66  $title = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_db'), count($clipboardElements));
67  foreach ($clipboardElements as $clipboardElement) {
68  $dataAttributes['clipboardItems'][] = [
69  'title' => $clipboardElement['title'],
70  'value' => $clipboardElement['value'],
71  ];
72  }
73  }
74 
75  $id = ‪StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
76 
77  return [
78  'iconIdentifier' => 'actions-document-paste-into',
79  'title' => $title,
80  'linkAttributes' => [
81  'id' => htmlspecialchars($id),
82  'data-element' => $dataAttributes['element'],
83  'data-clipboard-items' => json_encode($dataAttributes['clipboardItems']),
84  ],
85  'requireJsModules' => [
86  ['TYPO3/CMS/Backend/FormEngine/FieldControl/InsertClipboard' => 'function(FieldControl) {new FieldControl(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
87  ],
88  ];
89  }
90 
95  {
96  return ‪$GLOBALS['LANG'];
97  }
98 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:23
‪TYPO3\CMS\Backend\Form\FieldControl
Definition: AddRecord.php:3
‪TYPO3\CMS\Backend\Form\FieldControl\InsertClipboard
Definition: InsertClipboard.php:29
‪TYPO3\CMS\Backend\Form\FieldControl\InsertClipboard\render
‪array render()
Definition: InsertClipboard.php:35
‪TYPO3\CMS\Core\Utility\PathUtility\basename
‪static string basename($path)
Definition: PathUtility.php:164
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:91
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:21
‪TYPO3\CMS\Backend\Form\FieldControl\InsertClipboard\getLanguageService
‪LanguageService getLanguageService()
Definition: InsertClipboard.php:94