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