Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
doishub committed Nov 19, 2019
1 parent 37991f6 commit 3a37710
Show file tree
Hide file tree
Showing 5 changed files with 860 additions and 1 deletion.
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,88 @@
# contao-config-driver
# Config Driver for Contao Open Source CMS

This extension adds another driver to the Contao Open Source CMS.

With the Config-Driver it is possible to load fields from a configuration file and output them in the backend. The DCA structure used by Contao is kept. It can be decided whether the data is stored in the localconfig or in an existing database column.

For the storage in an existing database column, all fields of the configuration file are stored serialized.

### Example for saving in localconfig:
```
$GLOBALS['TL_DCA']['tl_newdca'] = array
(
'config' => array
(
'dataContainer' => 'Config',
'configFile' => 'dcaConfigFile' // Configuration-File: /templates/dcaConfigFile.php
)
);
```

### Example for saving in existing database table/column:

```
$GLOBALS['TL_DCA']['tl_newdca'] = array
(
'config' => array
(
'dataContainer' => 'Config',
'ptable' => 'tl_theme', // Table
'configField' => 'configData', // Column
'configFile' => 'dcaConfigFile' // Configuration-File: /templates/dcaConfigFile.php
)
);
```

### Example of a configuration file
```
return array(
'palettes' => array( //
'default' => '{font_legend},fontsize,fontcolor' // Optional
), //
'fields' => array(
'fontsize' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_newdca']['fontsize'],
'inputType' => 'inputUnit',
'options' => $GLOBALS['TL_CSS_UNITS'],
'eval' => array('includeBlankOption'=>true, 'rgxp'=>'digit_inherit', 'maxlength' => 20, 'tl_class'=>'w50'),
),
'fontcolor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_newdca']['fontcolor'],
'inputType' => 'text',
'eval' => array('maxlength'=>6, 'colorpicker'=>true, 'isHexColor'=>true, 'decodeEntities'=>true, 'tl_class'=>'w50 wizard'),
)
)
);
```

### Further Examples
To continue the example from above and to be able to call the configuration in the backend via the themes, we can add another icon for each theme.
##### config/config.php
```
$GLOBALS['BE_MOD']['design']['themes']['tables'][] = 'tl_newdca';
```

##### dca/tl_theme.php
```
// Add operation
$GLOBALS['TL_DCA']['tl_theme']['list']['operations']['newdca'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_theme']['newdca'],
'href' => 'table=tl_newdca',
'icon' => 'css.svg',
);
// Add fields
$GLOBALS['TL_DCA']['tl_theme']['fields']['configData'] = array
(
'inputType' => 'text',
'sql' => "text NULL"
);
```

##### Backend View
![Admin View: List](https://www.oveleon.de/share/github-assets/contao-config-driver-bundle/config-driver-example.png)

Now we can edit the configuration and use it as we like.
44 changes: 44 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name":"oveleon/contao-config-driver-bundle",
"type":"contao-bundle",
"description":"Config Driver for Contao Open Source CMS",
"keywords":["contao","driver","config"],
"homepage":"https://www.oveleon.de/",
"license":"MIT",
"authors":[
{
"name":"Oveleon",
"homepage":"https://oveleon.de/",
"role":"Developer"
}
],
"require":{
"php":"^5.6 || ^7.0",
"contao/core-bundle":"^4.4"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
},
"conflict": {
"contao/core": "*",
"contao/core-bundle": "4.4.1",
"contao/manager-plugin": "<2.0 || >=3.0"
},
"autoload":{
"psr-4": {
"Oveleon\\ContaoConfigDriverBundle\\": "src/"
},
"classmap": [
"src/Resources/contao/"
],
"exclude-from-classmap": [
"src/Resources/contao/config/",
"src/Resources/contao/dca/",
"src/Resources/contao/languages/",
"src/Resources/contao/templates/"
]
},
"extra":{
"contao-manager-plugin": "Oveleon\\ContaoConfigDriverBundle\\ContaoManager\\Plugin"
}
}
17 changes: 17 additions & 0 deletions src/ContaoConfigDriverBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao Config Driver Bundle.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoConfigDriverBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ContaoConfigDriverBundle extends Bundle
{
}
32 changes: 32 additions & 0 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao Config Driver Bundle.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoConfigDriverBundle\ContaoManager;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Oveleon\ContaoConfigDriverBundle\ContaoConfigDriverBundle;

class Plugin implements BundlePluginInterface
{
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser): array
{
return [
BundleConfig::create(ContaoConfigDriverBundle::class)
->setLoadAfter([ContaoCoreBundle::class])
->setReplace(['config-driver']),
];
}
}
Loading

0 comments on commit 3a37710

Please sign in to comment.