TYPO3 CMS  TYPO3_8-7
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 
21 
27 {
33  public function render()
34  {
35  $languageService = $this->getLanguageService();
36 
37  $parameterArray = $this->data['parameterArray'];
38  $elementName = $parameterArray['itemFormElName'];
39  $config = $parameterArray['fieldConf']['config'];
40  $internalType = (string)$config['internal_type'];
41  $clipboardElements = $config['clipboardElements'];
42 
43  if ((isset($config['readOnly']) && $config['readOnly'])
44  || empty($clipboardElements)
45  ) {
46  return [];
47  }
48 
49  $title = '';
50  $clipboardOnClick = [];
51  if ($internalType === 'file_reference' || $internalType === 'file') {
52  $title = sprintf($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_file'), count($clipboardElements));
53  foreach ($clipboardElements as $clipboardElement) {
54  $value = $clipboardElement['value'];
55  $title = 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(basename($clipboardElement['title']))) . ')';
56  $clipboardOnClick[] = 'setFormValueFromBrowseWin('
57  . GeneralUtility::quoteJSvalue($elementName) . ','
58  . 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(str_replace('%20', ' ', $value))) . '),'
59  . $title . ','
60  . $title
61  . ');';
62  }
63  } elseif ($internalType === 'db') {
64  $title = sprintf($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_db'), count($clipboardElements));
65  foreach ($clipboardElements as $clipboardElement) {
66  $value = $clipboardElement['value'];
67  $title = GeneralUtility::quoteJSvalue($clipboardElement['title']);
68  $clipboardOnClick[] = 'setFormValueFromBrowseWin('
69  . GeneralUtility::quoteJSvalue($elementName) . ','
70  . 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(str_replace('%20', ' ', $value))) . '),'
71  . $title . ','
72  . $title
73  . ');';
74  }
75  }
76  $clipboardOnClick[] = 'return false;';
77 
78  return [
79  'iconIdentifier' => 'actions-document-paste-into',
80  'title' => $title,
81  'linkAttributes' => [
82  'onClick' => implode('', $clipboardOnClick),
83  ],
84  ];
85  }
86 
90  protected function getLanguageService()
91  {
92  return $GLOBALS['LANG'];
93  }
94 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']