Commit 0cbda38c authored by Fabian Galinski's avatar Fabian Galinski 😾
Browse files

[FEATURE] Adapation of the Linkbrowser for TYPO3 8

parent 8943e7ed
......@@ -15,6 +15,7 @@ namespace SGalinski\Tinymce4Rte\Controller;
*/
use Psr\Http\Message\ServerRequestInterface;
use SGalinski\Tinymce4Rte\Utility\VersionUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -210,39 +211,60 @@ class BrowseLinksController extends AbstractLinkBrowserController {
return;
}
if (!empty($this->currentLinkParts['class'])) {
// remove required classes
$currentClasses = GeneralUtility::trimExplode(' ', $this->currentLinkParts['class'], true);
if (count($currentClasses) > 1) {
$this->currentLinkParts['class'] = end($currentClasses);
if (VersionUtility::isVersion870OrHigher()) {
if (!empty($this->currentLinkParts['url'])) {
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
$linkService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\LinkHandling\LinkService::class);
$data = $linkService->resolve($this->currentLinkParts['url']);
$this->currentLinkParts['type'] = $data['type'];
unset($data['type']);
$this->currentLinkParts['url'] = $data;
}
}
if (empty($this->currentLinkParts['data-htmlarea-external'])) {
// strip siteUrl prefix except for external and mail links
if (strpos($this->currentLinkParts['url'], 'mailto:') === false) {
$paramsPosition = strpos($this->currentLinkParts['url'], '?');
if ($paramsPosition !== false) {
$this->currentLinkParts['url'] = substr($this->currentLinkParts['url'], $paramsPosition + 1);
if (!empty($this->currentLinkParts['class'])) {
// Only keep last class value (others are automatically added again by required option)
// https://review.typo3.org/#/c/29643
$currentClasses = GeneralUtility::trimExplode(' ', $this->currentLinkParts['class'], true);
if (count($currentClasses) > 1) {
$this->currentLinkParts['class'] = end($currentClasses);
}
}
// special treatment for page links, remove the id= part
$idPosition = strpos($this->currentLinkParts['url'], 'id=');
if ($idPosition !== false) {
$this->currentLinkParts['url'] = substr($this->currentLinkParts['url'], $idPosition + 3);
} else {
if (!empty($this->currentLinkParts['class'])) {
// remove required classes
$currentClasses = GeneralUtility::trimExplode(' ', $this->currentLinkParts['class'], TRUE);
if (count($currentClasses) > 1) {
$this->currentLinkParts['class'] = end($currentClasses);
}
}
// in RTE the additional params are encoded directly at the end of the href part
// we need to split this again into dedicated fields
$additionalParamsPosition = strpos($this->currentLinkParts['url'], '?');
if ($additionalParamsPosition === false) {
$additionalParamsPosition = strpos($this->currentLinkParts['url'], '&');
}
if ($additionalParamsPosition !== false) {
$this->currentLinkParts['params'] = substr($this->currentLinkParts['url'], $additionalParamsPosition);
$this->currentLinkParts['url'] = substr($this->currentLinkParts['url'], 0, $additionalParamsPosition);
// in case the first sign was an ? override it with &
$this->currentLinkParts['params'][0] = '&';
if (empty($this->currentLinkParts['data-htmlarea-external'])) {
// strip siteUrl prefix except for external and mail links
if (strpos($this->currentLinkParts['url'], 'mailto:') === FALSE) {
$paramsPosition = strpos($this->currentLinkParts['url'], '?');
if ($paramsPosition !== FALSE) {
$this->currentLinkParts['url'] = substr($this->currentLinkParts['url'], $paramsPosition + 1);
}
}
// special treatment for page links, remove the id= part
$idPosition = strpos($this->currentLinkParts['url'], 'id=');
if ($idPosition !== FALSE) {
$this->currentLinkParts['url'] = substr($this->currentLinkParts['url'], $idPosition + 3);
}
// in RTE the additional params are encoded directly at the end of the href part
// we need to split this again into dedicated fields
$additionalParamsPosition = strpos($this->currentLinkParts['url'], '?');
if ($additionalParamsPosition === FALSE) {
$additionalParamsPosition = strpos($this->currentLinkParts['url'], '&');
}
if ($additionalParamsPosition !== FALSE) {
$this->currentLinkParts['params'] = substr($this->currentLinkParts['url'], $additionalParamsPosition);
$this->currentLinkParts['url'] = substr($this->currentLinkParts['url'], 0, $additionalParamsPosition);
// in case the first sign was an ? override it with &
$this->currentLinkParts['params'][0] = '&';
}
}
}
......@@ -589,4 +611,4 @@ class BrowseLinksController extends AbstractLinkBrowserController {
'contentTypo3Language' => $this->contentTypo3Language
];
}
}
\ No newline at end of file
}
......@@ -359,55 +359,56 @@ class RichTextElement extends AbstractFormElement {
* @return void
*/
protected function enableRegisteredPlugins() {
// $plugins = [
// @todo repair this
$plugins = [
// 'TYPO3Image' => [
// 'objectReference' => Typo3Image::class,
// ],
// 'TYPO3Link' => [
// 'objectReference' => TYPO3Link::class,
// ],
// ];
// foreach ($plugins as $pluginId => $pluginObjectConfiguration) {
// if (is_array($pluginObjectConfiguration) && isset($pluginObjectConfiguration['objectReference'])) {
// /** @var RteHtmlAreaApi $plugin */
// $plugin = GeneralUtility::makeInstance($pluginObjectConfiguration['objectReference']);
// $configuration = array(
// 'language' => $this->language,
// 'contentTypo3Language' => $this->contentTypo3Language,
// 'contentISOLanguage' => $this->contentISOLanguage,
// 'contentLanguageUid' => $this->contentLanguageUid,
// 'RTEsetup' => $this->vanillaRteTsConfig,
// 'client' => $this->client,
// 'thisConfig' => $this->processedRteConfiguration,
// 'specConf' => $this->defaultExtras,
// );
// if ($plugin->main($configuration)) {
// $this->registeredPlugins[$pluginId] = $plugin;
// // Override buttons from previously registered plugins
// $pluginButtons = GeneralUtility::trimExplode(',', $plugin->getPluginButtons(), TRUE);
// foreach ($this->pluginButton as $previousPluginId => $buttonList) {
// $this->pluginButton[$previousPluginId] = implode(',', array_diff(GeneralUtility::trimExplode(',', $this->pluginButton[$previousPluginId], TRUE), $pluginButtons));
// }
// $this->pluginButton[$pluginId] = $plugin->getPluginButtons();
// $pluginLabels = GeneralUtility::trimExplode(',', $plugin->getPluginLabels(), TRUE);
// foreach ($this->pluginLabel as $previousPluginId => $labelList) {
// $this->pluginLabel[$previousPluginId] = implode(',', array_diff(GeneralUtility::trimExplode(',', $this->pluginLabel[$previousPluginId], TRUE), $pluginLabels));
// }
// $this->pluginLabel[$pluginId] = $plugin->getPluginLabels();
// $this->pluginEnabledArray[] = $pluginId;
// }
// }
// }
//
// // Process overrides
// $hidePlugins = array();
// foreach ($this->registeredPlugins as $pluginId => $plugin) {
// /** @var RteHtmlAreaApi $plugin */
// if ($plugin->addsButtons() && !$this->pluginButton[$pluginId]) {
// $hidePlugins[] = $pluginId;
// }
// }
// $this->pluginEnabledArray = array_unique(array_diff($this->pluginEnabledArray, $hidePlugins));
'TYPO3Link' => [
'objectReference' => TYPO3Link::class,
],
];
foreach ($plugins as $pluginId => $pluginObjectConfiguration) {
if (is_array($pluginObjectConfiguration) && isset($pluginObjectConfiguration['objectReference'])) {
/** @var RteHtmlAreaApi $plugin */
$plugin = GeneralUtility::makeInstance($pluginObjectConfiguration['objectReference']);
$configuration = array(
'language' => $this->language,
'contentTypo3Language' => $this->contentTypo3Language,
'contentISOLanguage' => $this->contentISOLanguage,
'contentLanguageUid' => $this->contentLanguageUid,
'RTEsetup' => $this->vanillaRteTsConfig,
'client' => $this->client,
'thisConfig' => $this->processedRteConfiguration,
'specConf' => $this->defaultExtras,
);
if ($plugin->main($configuration)) {
$this->registeredPlugins[$pluginId] = $plugin;
// Override buttons from previously registered plugins
$pluginButtons = GeneralUtility::trimExplode(',', $plugin->getPluginButtons(), TRUE);
foreach ($this->pluginButton as $previousPluginId => $buttonList) {
$this->pluginButton[$previousPluginId] = implode(',', array_diff(GeneralUtility::trimExplode(',', $this->pluginButton[$previousPluginId], TRUE), $pluginButtons));
}
$this->pluginButton[$pluginId] = $plugin->getPluginButtons();
$pluginLabels = GeneralUtility::trimExplode(',', $plugin->getPluginLabels(), TRUE);
foreach ($this->pluginLabel as $previousPluginId => $labelList) {
$this->pluginLabel[$previousPluginId] = implode(',', array_diff(GeneralUtility::trimExplode(',', $this->pluginLabel[$previousPluginId], TRUE), $pluginLabels));
}
$this->pluginLabel[$pluginId] = $plugin->getPluginLabels();
$this->pluginEnabledArray[] = $pluginId;
}
}
}
// Process overrides
$hidePlugins = array();
foreach ($this->registeredPlugins as $pluginId => $plugin) {
/** @var RteHtmlAreaApi $plugin */
if ($plugin->addsButtons() && !$this->pluginButton[$pluginId]) {
$hidePlugins[] = $pluginId;
}
}
$this->pluginEnabledArray = array_unique(array_diff($this->pluginEnabledArray, $hidePlugins));
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment