‪TYPO3CMS  ‪main
LinkPopup.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 
21 use TYPO3\CMS\Backend\Form\Behavior\OnFieldChangeTrait;
27 
33 {
34  use OnFieldChangeTrait;
35 
36  public function ‪__construct(
37  private readonly ‪UriBuilder $uriBuilder,
38  ) {}
39 
45  public function ‪render(): array
46  {
47  $options = $this->data['renderData']['fieldControlOptions'];
48 
49  $title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.link';
50 
51  $parameterArray = $this->data['parameterArray'];
52  $itemName = $parameterArray['itemFormElName'];
53 
54  $linkBrowserArguments = [];
55  if (is_array($options['allowedTypes'] ?? false)) {
56  $linkBrowserArguments['allowedTypes'] = implode(',', $options['allowedTypes']);
57  } elseif (isset($options['blindLinkOptions'])) {
58  // @todo Deprecate this option
59  $linkBrowserArguments['blindLinkOptions'] = $options['blindLinkOptions'];
60  }
61  if (is_array($options['allowedOptions'] ?? false)) {
62  $linkBrowserArguments['allowedOptions'] = implode(',', $options['allowedOptions']);
63  } elseif (isset($options['blindLinkFields'])) {
64  // @todo Deprecate this option
65  $linkBrowserArguments['blindLinkFields'] = $options['blindLinkFields'];
66  }
67  if (is_array($options['allowedFileExtensions'] ?? false)) {
68  $linkBrowserArguments['allowedFileExtensions'] = implode(',', $options['allowedFileExtensions']);
69  } elseif (isset($options['allowedExtensions'])) {
70  // @todo Deprecate this option
71  $linkBrowserArguments['allowedExtensions'] = $options['allowedExtensions'];
72  }
73  $urlParameters = array_merge(
74  [
75  'params' => $linkBrowserArguments,
76  'table' => $this->data['tableName'],
77  'uid' => $this->data['databaseRow']['uid'],
78  'pid' => $this->data['databaseRow']['pid'],
79  'field' => $this->data['fieldName'],
80  'formName' => 'editform',
81  'itemName' => $itemName,
82  'hmac' => ‪GeneralUtility::hmac('editform' . $itemName, 'wizard_js'),
83  ],
84  $this->forwardOnFieldChangeQueryParams($parameterArray['fieldChangeFunc'] ?? [])
85  );
86  ‪$url = (string)$this->uriBuilder->buildUriFromRoute('wizard_link', ['P' => $urlParameters]);
87  $id = ‪StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
88  $label = $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_browse_links.xlf:openLinkWizard');
89  return [
90  'iconIdentifier' => 'actions-wizard-link',
91  'title' => $title,
92  'linkAttributes' => [
93  'id' => $id,
94  'href' => ‪$url,
95  'data-item-name' => $itemName,
96  'aria-label' => $label,
97  ],
98  'javaScriptModules' => [
99  ‪JavaScriptModuleInstruction::create('@typo3/backend/form-engine/field-control/link-popup.js')->instance('#' . $id),
100  ],
101  ];
102  }
103 
104  protected function ‪getLanguageService(): ‪LanguageService
105  {
106  return ‪$GLOBALS['LANG'];
107  }
108 }
‪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\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility\hmac
‪static string hmac($input, $additionalSecret='')
Definition: GeneralUtility.php:474
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57