Skip to content

Instantly share code, notes, and snippets.

@chriwo
Last active January 20, 2017 19:46
Show Gist options
  • Save chriwo/c563020784576277a088f3f9eff61952 to your computer and use it in GitHub Desktop.
Save chriwo/c563020784576277a088f3f9eff61952 to your computer and use it in GitHub Desktop.
Example to use the configuration options in extension manager

Using configuration option in the TYPO3 backend from the Extension Manager

Your extension need the following folder and file structur. The composer file optional, but is nice to have ;) and only a small version. For more details about the composer file have a look at the composer page.

More information and details about the configuration options could be found at the TYPO3 CoreApiReference.

your_extension
 |- Classes
 |   |- Domain
 |   |   |- Model
 |   |   |    |- Dto
 |   |   |       |- EmConfiguration.php
 |   |- Utility
 |        |- EmConfigurationUtility.php
 |- Resources
 |   |- Private
 |        |- Languages
 |            |- de.locallang_extmng.xlf
 |            |- locallang_extmng.xlf
 |- composer.json
 |- ext_conf_template.txt
 |- ext_localconf.php
{
"name": "vendor/your_ext_key",
"type": "typo3-cms-extension",
"description": "Little description of you extension",
"keywords": [
"TYPO3",
"extension"
],
"authors": [
{
"name": "Your name",
"role": "Developer"
}
],
"license": [
"GPL-2.0+"
],
"require": {
"typo3/cms-core": ">=7.6.0,<8.9.99"
}
"autoload": {
"psr-4": {
"VENDOR\\YourExtKey\\": "Classes"
}
}
}
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2016-02-11T08:53:40Z"
product-name="your_extkey">
<header/>
<body>
<trans-unit id="grids.oneColumn">
<target>Aktiviere das Einspaltige Grid von Gridelements</target>
</trans-unit>
<trans-unit id="grids.secondColumn">
<target>Aktiviere das Zweispaltige Grid von Gridelements</target>
</trans-unit>
</body>
</file>
</xliff>
<?php
namespace VENDOR\YourExtKey\Domain\Model\Dto;
/**
* Class EmConfiguration
*
* @package TYPO3
* @subpackage tx_extkey
*/
class EmConfiguration
{
/**
* @var bool
*/
protected $oneColumn;
/**
* @var bool
*/
protected $secondColumn;
/**
* Fill the properties properly
*
* @param array $configuration em configuration
*/
public function __construct(array $configuration)
{
foreach ($configuration as $key => $value) {
if (property_exists(__CLASS__, $key)) {
$this->$key = $value;
}
}
}
/**
* Returns the flag if the oneColumn is active
* @return bool
*/
public function isOneColumn()
{
return $this->oneColumn;
}
/**
* Sets the flag for oneColumn
* @param bool $oneColumn
* @return void
*/
public function setOneColumn($oneColumn)
{
$this->oneColumn = $oneColumn;
}
/**
* Returns the flag if the secondColumn is active
* @return bool
*/
public function isSecondColumn()
{
return $this->secondColumn;
}
/**
* Sets the flag for secondColumn
* @param bool secondColumn
* @return void
*/
public function setSecondColumn($secondColumn)
{
$this->secondColumn = $secondColumn;
}
}
<?php
namespace VENDOR\YourExtKey\Utility;
use VENDOR\YourExtKey\Domain\Model\Dto\EmConfiguration;;
/**
* Class EmConfiguration
*
* @package TYPO3
* @subpackage tx_extkey
*/
class EmConfigurationUtility
{
/**
* Parses the extension settings.
*
* @return \VENDOR\YourExtKey\Domain\Model\Dto\EmConfiguration
* @throws \Exception If the configuration is invalid.
*/
public static function getSettings()
{
$settings = new EmConfiguration(self::parseSettings());
return $settings;
}
/**
* Parse settings and return it as array
*
* @return array unserialized extconf settings
*/
public static function parseSettings()
{
$settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['your_extkey']);
if (!is_array($settings)) {
$settings = [];
}
return $settings;
}
}
# cat=grids/enable/10; type=boolean; label=LLL:EXT:your_extkey/Resources/Private/Language/locallang_extmng.xlf:grids.oneColumn
oneColumn = 0
# cat=grids/enable/11; type=boolean; label=LLL:EXT:your_extkey/Resources/Private/Language/locallang_extmng.xlf:grids.secondColumn
secondColumn = 0
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied');
}
/**@var \VENDOR\YourExtKey\Domain\Model\Dto\EmConfiguration $configuration*/
$configuration = \VENDOR\YourExtKey\Utility\EmConfigurationUtility::getSettings();
/* ==================================================================================
Load grid layout from extension manager configurations, if gridelements is loaded
===================================================================================== */
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('gridelements')) {
if ($configuration->isOneColumn()) {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . '/Configuration/TypoScript/PageTS/OneColumnGridLayout.ts2">'
);
}
if ($configuration->isSecondColumn()) {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . '/Configuration/TypoScript/PageTS/SecondColumnGridLayout.ts2">'
);
}
}
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2016-02-11T08:53:40Z"
product-name="your_extkey">
<header/>
<body>
<trans-unit id="grids.oneColumn">
<source>Activate the gridelement configuration for a one column grid</source>
</trans-unit>
<trans-unit id="grids.secondColumn">
<source>Activate the gridelement configuration for a two column grid</source>
</trans-unit>
</body>
</file>
</xliff>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment