Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
doishub committed Sep 10, 2019
1 parent eeffbba commit 6378771
Show file tree
Hide file tree
Showing 18 changed files with 1,099 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Contao Component Style Manager
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-component-style-manager",
"type":"contao-bundle",
"description":"Style and CSS-Class Manager for Contao Open Source CMS",
"keywords":["contao","styles","css","manager"],
"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\\ContaoComponentStyleManager\\": "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\\ContaoComponentStyleManager\\ContaoManager\\Plugin"
}
}
17 changes: 17 additions & 0 deletions src/ContaoComponentStyleManager.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 ContaoComponentStyleManager.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoComponentStyleManager;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ContaoComponentStyleManager 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 ContaoComponentStyleManager.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoComponentStyleManager\ContaoManager;

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

class Plugin implements BundlePluginInterface
{
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser): array
{
return [
BundleConfig::create(ContaoComponentStyleManager::class)
->setLoadAfter([ContaoCoreBundle::class])
->setReplace(['componentStyleManager']),
];
}
}
48 changes: 48 additions & 0 deletions src/Resources/contao/classes/StyleManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*
* This file is part of ContaoComponentStyleManager.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoComponentStyleManager;

class StyleManager
{
/**
* Add CSS-Class (fe_page)
*
* @param $objPage
* @param $objLayout
* @param $objPageRegular
*/
public function generatePage($objPage, $objLayout, $objPageRegular)
{
$objPage->cssClass = $objPage->cssClass ? $objPage->cssClass . ' ' . $objPage->styleManagerCompiled : $objPage->styleManagerCompiled;
}

/**
* Add CSS-Class (mod_article)
*
* @param $objRow
*/
public function getArticle($objRow)
{
$arrCSS = \StringUtil::deserialize($objRow->cssID, true);
$arrCSS[1] = trim($arrCSS[1] . ' ' . $objRow->styleManagerCompiled);
$objRow->cssID = serialize($arrCSS);
}

/**
* Add CSS-Class (ce_)
*
* @param $objTemplate
*/
public function parseTemplate($objTemplate)
{
if(isset($objTemplate->typePrefix) && $objTemplate->typePrefix === 'ce_' && $objTemplate->styleManagerCompiled)
{
$objTemplate->class .= ' ' . $objTemplate->styleManagerCompiled;
}
}
}
38 changes: 38 additions & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
* This file is part of ContaoComponentStyleManager.
*
* (c) https://www.oveleon.de/
*/

// Back end modules
array_insert($GLOBALS['BE_MOD'], count($GLOBALS['BE_MOD']['design']), array
(
'design' => array
(
'style_manager' => array
(
'tables' => array('tl_style_manager')
),
)
));

// Back end form fields
array_insert($GLOBALS['BE_FFL'], 1, array
(
'stylemanager' => '\\Oveleon\\ContaoComponentStyleManager\\ComponentStyleSelect'
));

// Models
$GLOBALS['TL_MODELS']['tl_style_manager'] = '\\Oveleon\\ContaoComponentStyleManager\\StyleManagerModel';

// Hooks
$GLOBALS['TL_HOOKS']['generatePage'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'generatePage');
$GLOBALS['TL_HOOKS']['getArticle'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'getArticle');
$GLOBALS['TL_HOOKS']['parseTemplate'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'parseTemplate');

// Style sheet
if (TL_MODE == 'BE')
{
$GLOBALS['TL_CSS'][] = 'bundles/contaocomponentstylemanager/stylemanager.css|static';
}
87 changes: 87 additions & 0 deletions src/Resources/contao/dca/tl_article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/*
* This file is part of ContaoComponentStyleManager.
*
* (c) https://www.oveleon.de/
*/

// Extend the regular palette
$palette = Contao\CoreBundle\DataContainer\PaletteManipulator::create()
->addLegend('style_manager_legend', 'expert_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)
->addField(array('styleManager'), 'style_manager_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', 'tl_article');

// Extend fields
array_insert($GLOBALS['TL_DCA']['tl_article']['fields'], 0, array
(
'styleManager' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_article']['styleManager'],
'exclude' => true,
'inputType' => 'stylemanager',
'onload_callback' => array
(
array('tl_style_manager_article', 'checkPermission')
),
'save_callback' => array
(
array('tl_style_manager_article', 'updateStyleManager')
),
'eval' => array('tl_class'=>'clr stylemanager'),
'sql' => "blob NULL"
),
'styleManagerCompiled' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_article']['styleManagerCompiled'],
'exclude' => true,
'inputType' => 'text',
'sql' => "varchar(255) NOT NULL default ''"
)
));

/**
* Provide miscellaneous methods that are used by the data configuration array.
*
* @author Daniele Sciannimanica <[email protected]>
*/
class tl_style_manager_article extends \Backend
{
/**
* Import the back end user object
*/
public function __construct()
{
parent::__construct();
$this->import('BackendUser', 'User');
}

/**
* Check permissions to edit table tl_real_estate_group
*
* @throws Contao\CoreBundle\Exception\AccessDeniedException
*/
public function checkPermission()
{
return;
}

/**
* Update StyleManager compiled-Field
*
* @param mixed $varValue
* @param DataContainer $dc
*
* @return mixed
*/
public function updateStyleManager($varValue, DataContainer $dc)
{
$varValues = \StringUtil::deserialize($varValue, true);
$varValues = array_filter($varValues);

// Store the new classes
$this->Database->prepare("UPDATE tl_article SET styleManagerCompiled=? WHERE id=?")
->execute(implode(' ', $varValues), $dc->id);

return $varValue;
}
}
95 changes: 95 additions & 0 deletions src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/*
* This file is part of ContaoComponentStyleManager.
*
* (c) https://www.oveleon.de/
*/

// Extend the regular palette
$palette = Contao\CoreBundle\DataContainer\PaletteManipulator::create()
->addLegend('style_manager_legend', 'expert_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_BEFORE)
->addField(array('styleManager'), 'style_manager_legend', Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND);

foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $key=>$value){
if($key === '__selector__')
{
continue;
}

$palette->applyToPalette($key, 'tl_content');
}

// Extend fields
array_insert($GLOBALS['TL_DCA']['tl_content']['fields'], 0, array
(
'styleManager' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_article']['styleManager'],
'exclude' => true,
'inputType' => 'stylemanager',
'onload_callback' => array
(
array('tl_style_manager_content', 'checkPermission')
),
'save_callback' => array
(
array('tl_style_manager_content', 'updateStyleManager')
),
'eval' => array('tl_class'=>'clr stylemanager'),
'sql' => "blob NULL"
),
'styleManagerCompiled' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_article']['styleManagerCompiled'],
'exclude' => true,
'inputType' => 'text',
'sql' => "varchar(255) NOT NULL default ''"
)
));

/**
* Provide miscellaneous methods that are used by the data configuration array.
*
* @author Daniele Sciannimanica <[email protected]>
*/
class tl_style_manager_content extends \Backend
{
/**
* Import the back end user object
*/
public function __construct()
{
parent::__construct();
$this->import('BackendUser', 'User');
}

/**
* Check permissions to edit table tl_real_estate_group
*
* @throws Contao\CoreBundle\Exception\AccessDeniedException
*/
public function checkPermission()
{
return;
}

/**
* Update StyleManager compiled-Field
*
* @param mixed $varValue
* @param DataContainer $dc
*
* @return mixed
*/
public function updateStyleManager($varValue, DataContainer $dc)
{
$varValues = \StringUtil::deserialize($varValue, true);
$varValues = array_filter($varValues);

// Store the new classes
$this->Database->prepare("UPDATE tl_content SET styleManagerCompiled=? WHERE id=?")
->execute(implode(' ', $varValues), $dc->id);

return $varValue;
}
}
Loading

0 comments on commit 6378771

Please sign in to comment.