Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
iCodr8 committed May 29, 2016
0 parents commit 77102fe
Show file tree
Hide file tree
Showing 23 changed files with 1,066 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# OS
.DS_Store
Thumbs.db

# IDEs
.buildpath
.project
.settings/
.build/
.external*/
.idea/
nbproject/

# composer related
vendor/

# build
build/
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2014-2016 Daniel Kiesel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Contao 4 Css Style Selector Bundle
=======================

This Contao extension is a CSS style selector for content elements in Contao.

### CSS styles can be defined here

![css selector navigation](https://raw.githubusercontent.com/Craffft/css-style-selector-bundle/master/docs/css-style-selector-nav.png)

### The predefined styles can be selected here

![css selector navigation](https://raw.githubusercontent.com/Craffft/css-style-selector-bundle/master/docs/css-style-selector-preview.png)


Installation
------------

### Step 1: Download the Bundle

Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:

```bash
$ composer require craffft/css-style-selector-bundle "dev-master"
```

This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.

### Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles
in the `app/AppKernel.php` file of your project:

```php
<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...

new Craffft\CssStyleSelectorBundle\CraffftCssStyleSelectorBundle(),
);

// ...
}

// ...
}
```
34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "craffft/css-style-selector-bundle",
"type": "symfony-bundle",
"description": "Contao 4 Css Style Selector bundle",
"keywords": ["css", "selector", "list", "classes"],
"license": "MIT",
"authors": [
{
"name": "Daniel Kiesel",
"homepage": "https://github.com/iCodr8"
}
],
"support": {
"issues": "https://github.com/Craffft/css-style-selector-bundle/issues",
"source": "https://github.com/Craffft/css-style-selector-bundle"
},
"require": {
"php": ">=5.4.0",
"contao/core-bundle": "~4.1"
},
"conflict": {
"contao/core": "*"
},
"autoload": {
"psr-4": {
"Craffft\\CssStyleSelectorBundle\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-develop": "4.2.x-dev"
}
}
}
Binary file added docs/css-style-selector-nav.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/css-style-selector-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/css-style-selector-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/CraffftCssStyleSelectorBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the CssStyleSelector Bundle.
*
* (c) Daniel Kiesel <https://github.com/iCodr8>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Craffft\CssStyleSelectorBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Configures the Craffft Css Style Selector Bundle.
*/
class CraffftCssStyleSelectorBundle extends Bundle
{
}
38 changes: 38 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the CssStyleSelector Bundle.
*
* (c) Daniel Kiesel <https://github.com/iCodr8>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Craffft\CssStyleSelectorBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('craffft_css_style_selector');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
97 changes: 97 additions & 0 deletions src/Models/CssStyleSelectorModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/*
* This file is part of the CssStyleSelector Bundle.
*
* (c) Daniel Kiesel <https://github.com/iCodr8>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Craffft\CssStyleSelectorBundle\Models;

use Contao\Database;
use Contao\Model;

class CssStyleSelectorModel extends Model
{
const TYPE_ARTICLE = 'article';
const TYPE_CONTENT = 'content';
const TYPE_LAYOUT = 'layout';
const TYPE_NEWS = 'news';
const TYPE_MODEL = 'module';
const TYPE_PAGE = 'page';

/**
* Name of the table
* @var string
*/
protected static $strTable = 'tl_css_style_selector';

public static function getAvailableTypes()
{
return array(
self::TYPE_ARTICLE,
self::TYPE_CONTENT,
self::TYPE_LAYOUT,
self::TYPE_NEWS,
self::TYPE_MODEL,
self::TYPE_PAGE
);
}

/**
* @param array $arrIds
* @return array
*/
public static function findCssClassesByIds(array $arrIds)
{
$t = self::$strTable;
$objDatabase = Database::getInstance();

$objCssStyleSelector = $objDatabase->prepare("SELECT cssClasses FROM $t WHERE id IN(". implode(',', array_map('intval', array_unique($arrIds))) .")")->execute();

return $objCssStyleSelector->fetchEach('cssClasses');
}

/**
* @param $strType
* @return array
*/
public static function findCssClassesByNotDisabledType($strType)
{
if (!in_array($strType, self::getAvailableTypes())) {
return array();
}

$t = self::$strTable;
$objDatabase = Database::getInstance();

$objCssStyleSelector = $objDatabase
->prepare("SELECT cssClasses FROM $t WHERE disableIn" . ucfirst($strType) . "=?")
->execute(0);

return $objCssStyleSelector->fetchEach('cssClasses');
}

/**
* @param $strType
* @return array
*/
public static function findStyleDesignationByNotDisabledType($strType)
{
if (!in_array($strType, self::getAvailableTypes())) {
return array();
}

$t = self::$strTable;
$objDatabase = Database::getInstance();

$objCssStyleSelector = $objDatabase
->prepare("SELECT id, styleDesignation FROM $t WHERE disableIn" . ucfirst($strType) . "=? ORDER BY styleDesignation ASC")
->execute(0);

return $objCssStyleSelector->fetchEach('styleDesignation');
}
}
16 changes: 16 additions & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the CssStyleSelector Bundle.
*
* (c) Daniel Kiesel <https://github.com/iCodr8>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

$GLOBALS['BE_MOD']['design']['cssStyleSelector'] = array
(
'tables' => array('tl_css_style_selector'),
'icon' => 'bundles/craffftcssstyleselector/icon.png'
);
37 changes: 37 additions & 0 deletions src/Resources/contao/dca/tl_article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the CssStyleSelector Bundle.
*
* (c) Daniel Kiesel <https://github.com/iCodr8>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (isset($GLOBALS['TL_DCA']['tl_article'])) {
// Palettes
foreach ($GLOBALS['TL_DCA']['tl_article']['palettes'] as $k => $v) {
$GLOBALS['TL_DCA']['tl_article']['palettes'][$k] = str_replace(',cssID', ',cssStyleSelector,cssID', $v);
}

// Fields
$GLOBALS['TL_DCA']['tl_article']['fields']['cssStyleSelector'] = array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['cssStyleSelector'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => function () {
return \Craffft\CssStyleSelectorBundle\Models\CssStyleSelectorModel::findStyleDesignationByNotDisabledType(
\Craffft\CssStyleSelectorBundle\Models\CssStyleSelectorModel::TYPE_ARTICLE
);
},
'search' => true,
'eval' => array('chosen' => true, 'multiple' => true, 'tl_class' => 'clr'),
'save_callback' => array
(
array('Craffft\\CssStyleSelectorBundle\\Util\\CssStyleSelectorUtil', 'saveCssIdCallback')
),
'sql' => "blob NULL"
);
}
37 changes: 37 additions & 0 deletions src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the CssStyleSelector Bundle.
*
* (c) Daniel Kiesel <https://github.com/iCodr8>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (isset($GLOBALS['TL_DCA']['tl_content'])) {
// Palettes
foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $k => $v) {
$GLOBALS['TL_DCA']['tl_content']['palettes'][$k] = str_replace(',cssID', ',cssStyleSelector,cssID', $v);
}

// Fields
$GLOBALS['TL_DCA']['tl_content']['fields']['cssStyleSelector'] = array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['cssStyleSelector'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => function () {
return \Craffft\CssStyleSelectorBundle\Models\CssStyleSelectorModel::findStyleDesignationByNotDisabledType(
\Craffft\CssStyleSelectorBundle\Models\CssStyleSelectorModel::TYPE_CONTENT
);
},
'search' => true,
'eval' => array('chosen' => true, 'multiple' => true, 'tl_class' => 'clr'),
'save_callback' => array
(
array('Craffft\\CssStyleSelectorBundle\\Util\\CssStyleSelectorUtil', 'saveCssIdCallback')
),
'sql' => "blob NULL"
);
}
Loading

0 comments on commit 77102fe

Please sign in to comment.