Commit 26ba6d1f authored by Fabian Galinski's avatar Fabian Galinski 😾
Browse files

[FEATURE] Adds a possibility to set default link parameters or additions

parent 3f5ce7e8
......@@ -27,6 +27,8 @@ namespace SGalinski\SgContentlink\UserFunc;
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Extbase\Service\TypoScriptService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
......@@ -38,6 +40,42 @@ class ContentElementRendering {
*/
public $cObj;
/**
* @var array
*/
protected $overwrites = array();
/**
* @var array
*/
protected $additions = array();
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager;
public function __construct() {
$this->objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
/** @var TypoScriptService $typoScriptService */
$class = 'TYPO3\CMS\Extbase\Service\TypoScriptService';
$typoScriptService = $this->objectManager->get($class);
/** @var BackendConfigurationManager $configurationManager */
$class = 'TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager';
$configurationManager = $this->objectManager->get($class);
$settings = $typoScriptService->convertTypoScriptArrayToPlainArray($configurationManager->getTypoScriptSetup());
if (version_compare(TYPO3_branch, '7.6', '<')) {
$this->overwrites = $settings['plugin.']['tx_sgcontentlink.']['settings.']['link.']['overwrite.'];
$this->additions = $settings['plugin.']['tx_sgcontentlink.']['settings.']['link.']['add.'];
} else {
$this->overwrites = $settings['plugin']['tx_sgcontentlink']['settings']['link']['overwrite'];
$this->additions = $settings['plugin']['tx_sgcontentlink']['settings']['link']['add'];
}
}
/**
* Adds parameters to the current content element.
*
......@@ -53,6 +91,55 @@ class ContentElementRendering {
$content = preg_replace('/<a.+?>/is', '', $content);
$content = str_replace('</a>', '', $content);
return $this->cObj->getTypoLink($content, $this->cObj->data['tx_sgcontentlink_contentlink']);
return $this->cObj->getTypoLink($content, implode(' ', $this->getParameters()));
}
/**
* Returns the parameters for the typo link.
*
* @return array
*/
protected function getParameters() {
$parameters = str_getcsv($this->cObj->data['tx_sgcontentlink_contentlink'], ' ', '"');
$defaultTarget = $this->overwrites['defaultTarget'];
if ($defaultTarget) {
$parameters[1] = $defaultTarget;
} elseif (!isset($parameters[1])) {
$parameters[1] = '-';
}
$defaultClass = $this->overwrites['defaultClass'];
$addClass = $this->additions['class'];
$classIsSet = isset($parameters[2]);
if ($defaultClass) {
$parameters[2] = $defaultClass;
} elseif ($classIsSet && $addClass) {
$parameters[2] .= ' ' . $addClass;
} elseif (!$classIsSet && $addClass) {
$parameters[2] = $addClass;
} elseif (!$classIsSet) {
$parameters[2] = '-';
}
$defaultTitle = $this->overwrites['defaultTitle'];
$addTitle = $this->additions['title'];
$titleIsSet = isset($parameters[3]);
if ($defaultTitle) {
$parameters[3] = $defaultTitle;
} elseif ($titleIsSet && $addTitle) {
$parameters[3] .= ' ' . $addTitle;
} elseif (!$titleIsSet && $addTitle) {
$parameters[3] = $addTitle;
}
foreach ($parameters as &$parameter) {
if ($parameter === '-' || strpos($parameter, ' ') === FALSE) {
continue;
}
$parameter = '"' . $parameter . '"';
}
return $parameters;
}
}
\ No newline at end of file
}
plugin.tx_sgcontentlink {
settings {
link {
overwrite {
defaultTarget =
defaultClass =
defaultTitle =
}
add {
class =
title =
}
}
}
}
# Change page rendering with user function
tt_content.stdWrap.postUserFunc = SGalinski\SgContentlink\UserFunc\ContentElementRendering->wrapContentLinkAroundContent
\ No newline at end of file
tt_content.stdWrap.postUserFunc = SGalinski\SgContentlink\UserFunc\ContentElementRendering->wrapContentLinkAroundContent
plugin.tx_sgcontentlink {
settings {
link {
overwrite {
defaultTarget = {$plugin.tx_sgcontentlink.settings.link.overwrite.defaultTarget}
defaultClass = {$plugin.tx_sgcontentlink.settings.link.overwrite.defaultClass}
defaultTitle = {$plugin.tx_sgcontentlink.settings.link.overwrite.defaultTitle}
}
add {
class = {$plugin.tx_sgcontentlink.settings.link.add.class}
title = {$plugin.tx_sgcontentlink.settings.link.add.title}
}
}
}
}
......@@ -14,7 +14,7 @@ $EM_CONF[$_EXTKEY] = array (
'title' => 'sgalinski Contentlink',
'description' => 'Possibility to set a link around a whole content element. (Include static template)',
'category' => 'plugin',
'version' => '1.2.0',
'version' => '1.3.0',
'state' => 'stable',
'uploadfolder' => false,
'createDirs' => '',
......
Markdown is supported
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