Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MDevster committed Nov 23, 2017
1 parent 75eb4cb commit 7e339cc
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{php,twig,yml}]
indent_style = space
indent_size = 4

[*.{html5,svg,min.css,min.js}]
insert_final_newline = false
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Composer
/composer.lock
/vendor/

# PhpUnit
/phpunit.xml

# PhpStorm
.idea
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# pdir/contao-theme-helper-bundle

add helper functions for contao themes

# german version

## Verwendung

Globale Inhalte werden über Ordner verwaltet und jeder Bereich bekommt
einen eigenen Artikel und ein Theme Tag zugewiesen. Über die
Artikeleigenschaften können verfügbare Tags zugewiesen werden.

### Aufbau Tag

THEME/BEREICH/ID

##### Beispiel

Mate Theme

MATE01/01 Kopfbereich Öffnungszeiten

##### Insert Tag
{{theme::content::MATE01/01}}

### verfügbare Tags

Tags werden von den verfügbaren Themes in der config.php registriert.

# Available Themes
- Mate Theme für Contao | Tags

# english version
44 changes: 44 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "pdir/contao-theme-helper-bundle",
"type":"contao-bundle",
"description": "pdir theme helper bundle for Contao 4",
"keywords":["contao","theme","template", "tools", "helper"],
"homepage": "https://pdir.de",
"license": "LGPL-3.0+",
"authors": [
{
"name": "Webdesign für Dresden",
"homepage": "https://pdir.de",
"email" : "[email protected]",
"role" : "Developer"
}
],
"support" : {
"email" : "[email protected]",
"issues" : "https://github.com/pdir/contao-theme-helper-bundle/issues",
"source" : "https://github.com/pdir/contao-theme-helper-bundle"
},
"require": {
"php": ">=7.4.0",
"contao/core-bundle": "^4.4"
},
"conflict": {
"contao/core": "*"
},
"autoload": {
"psr-4": {
"Pdir\\Contao\\ThemeHelperBundle\\ThemeHelperBundle\\": "src/"
},
"classmap": [
"src/Resources/contao/"
]
},
"extra": {
"contao-manager-plugin": "Pdir\\Contao\\ThemeHelperBundle\\ContaoManager\\Plugin"
},
"config": {
"files": "files"
},
"prefer-stable": true,
"minimum-stability": "dev"
}
40 changes: 40 additions & 0 deletions src/Pdir/Contao/ThemeHelperBundle/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* Theme Helper Bundle for Contao Open Source CMS
*
* Copyright (C) 2017 pdir / digital agentur <[email protected]>
*
* @package pdir/contao-theme-helper-bundle
* @link https://github.com/pdir/contao-theme-helper-bundle
* @license LGPL-3.0+
* @author Mathias Arzberger <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pdir\Contao\ThemeHelperBundle;

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

/**
* Plugin for the Contao Manager.
*
* @author Mathias Arzberger <[email protected]>
*/
class Plugin implements BundlePluginInterface
{
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser)
{
return [
BundleConfig::create(ThemeHelperBundle::class)
->setLoadAfter([ThemeHelperBundle::class])
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* Theme Helper Bundle for Contao Open Source CMS
*
* Copyright (C) 2017 pdir / digital agentur <[email protected]>
*
* @package pdir/contao-theme-helper-bundle
* @link https://github.com/pdir/contao-theme-helper-bundle
* @license LGPL-3.0+
* @author Mathias Arzberger <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pdir\Contao\ThemeHelperBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/**
* Adds the bundle services to the container.
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class ThemeHelperExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $mergedConfig, ContainerBuilder $container)
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);
$loader->load('listener.yml');
$loader->load('services.yml');
}
}
102 changes: 102 additions & 0 deletions src/Pdir/Contao/ThemeHelperBundle/EventListener/InsertTagsListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/**
* Theme Helper Bundle for Contao Open Source CMS
*
* Copyright (C) 2017 pdir / digital agentur <[email protected]>
*
* @package pdir/contao-theme-helper-bundle
* @link https://github.com/pdir/contao-theme-helper-bundle
* @license LGPL-3.0+
* @author Mathias Arzberger <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Pdir\Contao\ThemeHelperBundle\EventListener;

use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
use Contao\Events;
use Contao\StringUtil;

/**
* Handles insert tags for themes.
*
* @author Mathias Arzberger <[email protected]>
*/
class InsertTagsListener
{
/**
* @var ContaoFrameworkInterface
*/
private $framework;
/**
* @var array
*/
private $supportedTags = [
'theme',
];
/**
* Constructor.
*
* @param ContaoFrameworkInterface $framework
*/
public function __construct(ContaoFrameworkInterface $framework)
{
$this->framework = $framework;
}
/**
* Replaces theme insert tags.
*
* @param string $tag
*
* @return string|false
*/
public function onReplaceInsertTags($tag)
{
$elements = explode('::', $tag);
$key = strtolower($elements[0]);
if (in_array($key, $this->supportedTags, true)) {
return $this->replaceThemeInsertTag($key, $elements[1], $elements[2]);
}
return false;
}
/**
* Replaces an event-related insert tag.
*
* @param string $tagType
* @param string $themeTag
*
* @return string
*/
private function replaceThemeInsertTag($tagType, $themeTag)
{
$this->framework->initialize();
switch ($tagType) {
// get article content by theme helper tag
case 'content':
/** @var ArticleModel $adapter */
$adapter = $this->framework->getAdapter(ArticleModel::class);
if (null === ($article = $adapter->findOneBy('pdir_th_tag', $themeTag))) {
return '';
}
return $this->generateArticleReplacement($article);
break;
}
return false;
}
/**
* Generates the article replacement string.
*
* @param ArticleModel $article
*
* @return string
*/
private function generateArticleReplacement(ArticleModel $article)
{
/** @var Article $adapter */
$adapter = $this->framework->getAdapter(Article::class);
return $adapter->getArticle($article);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
contao_calendar.listener.insert_tags:
class: Pdir\Contao\ThemeHelperBundle\EventListener\InsertTagsListener
arguments:
- "@contao.framework"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
_instanceof:
Contao\CoreBundle\Framework\FrameworkAwareInterface:
calls:
- ["setFramework", ["@contao.framework"]]
28 changes: 28 additions & 0 deletions src/Pdir/Contao/ThemeHelperBundle/ThemeHelperBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* THEME_NAME for Contao Open Source CMS
*
* Copyright (C) 2017 pdir / digital agentur <[email protected]>
*
* @package pdir/contao-theme-helper-bundle
* @link https://github.com/pdir/contao-theme-helper-bundle
* @license LGPL-3.0+
* @author Mathias Arzberger <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types = 1);

namespace Pdir\Contao\ThemeHelperBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Configures the ThemeHelper bundle.
*
* @author Mathias Arzberger <[email protected]>
*/
class ThemeHelperBundle extends Bundle
{
}

0 comments on commit 7e339cc

Please sign in to comment.