Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for forms and controllers + event listeners #23

Open
wants to merge 17 commits into
base: develop-v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 0 additions & 183 deletions src/Columns.php

This file was deleted.

113 changes: 113 additions & 0 deletions src/Controller/ContentElement/ColumnStartController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/*
* Copyright MADE/YOUR/DAY OG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MadeYourDay\RockSolidColumns\Controller\ContentElement;

use Contao\BackendTemplate;
use Contao\ContentModel;
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController;
use Contao\CoreBundle\Image\Studio\Studio;
use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\CoreBundle\ServiceAnnotation\ContentElement;
use Contao\StringUtil;
use Contao\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* Column start content element
*
* @author Martin Auswöger <[email protected]>
*
* @ContentElement("rs_column_start", category="rs_columns")
*/
class ColumnStartController extends AbstractContentElementController
{
private ScopeMatcher $scopeMatcher;
private Studio $studio;

public function __construct(ScopeMatcher $scopeMatcher, Studio $studio)
{
$this->scopeMatcher = $scopeMatcher;
$this->studio = $studio;
}

protected function getResponse(Template $template, ContentModel $model, Request $request): ?Response
{
if ($this->scopeMatcher->isBackendRequest($request)) {
$backendTemplate = new BackendTemplate('be_wildcard');
$backendTemplate->title = $template->headline;
return new Response($backendTemplate->parse());
}

$classes = array('rs-column');
$styles = array();
$parentKey = ($model->ptable ?: 'tl_article') . '__' . $model->pid;

if (isset($GLOBALS['TL_RS_COLUMNS'][$parentKey]) && $GLOBALS['TL_RS_COLUMNS'][$parentKey]['active']) {

$GLOBALS['TL_RS_COLUMNS'][$parentKey]['active'] = false;
$GLOBALS['TL_RS_COLUMNS'][$parentKey]['count']++;

$count = $GLOBALS['TL_RS_COLUMNS'][$parentKey]['count'];
foreach ($GLOBALS['TL_RS_COLUMNS'][$parentKey]['config'] as $name => $media) {
$classes = array_merge($classes, $media[($count - 1) % count($media)]);
if ($count - 1 < count($media)) {
$classes[] = '-' . $name . '-first-row';
}
}

}
else {
trigger_error('Missing column wrapper start element before column start element ID ' . $model->id . '.', E_USER_WARNING);
}

if ($model->rs_column_color_inverted) {
$classes[] = '-color-inverted';
}

if ($model->rs_column_background) {

$backgroundColor = StringUtil::deserialize($model->rs_column_background_color);
if (is_array($backgroundColor) && $backgroundColor[0]) {
$styles[] = 'background-color: #' . $backgroundColor[0] . ';';
}

if (trim($model->rs_column_background_image)) {
$figure = $this->studio
rabauss marked this conversation as resolved.
Show resolved Hide resolved
->createFigureBuilder()
->fromUuid($model->rs_column_background_image ?: '')
->setSize($model->rs_column_background_image_size)
->enableLightbox(false)
->buildIfResourceExists()
;
if (null !== $figure) {
$styles[] = 'background-image: url(&quot;' . $figure->getImage()->getImageSrc(true) . '&quot;);';
}
}

if ($model->rs_column_background_size) {
$styles[] = 'background-size: ' . $model->rs_column_background_size . ';';
}

if ($model->rs_column_background_position) {
$styles[] = 'background-position: ' . $model->rs_column_background_position . ';';
}

if ($model->rs_column_background_repeat) {
$styles[] = 'background-repeat: ' . $model->rs_column_background_repeat . ';';
}

}

$template->class .= ' ' . implode(' ', $classes);
$template->style = implode(' ', $styles);

return new Response($template->parse());
}
}
54 changes: 54 additions & 0 deletions src/Controller/ContentElement/ColumnStopController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/*
* Copyright MADE/YOUR/DAY OG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MadeYourDay\RockSolidColumns\Controller\ContentElement;

use Contao\BackendTemplate;
use Contao\ContentModel;
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController;
use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\CoreBundle\ServiceAnnotation\ContentElement;
use Contao\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* Column stop content element
*
* @author Martin Auswöger <[email protected]>
*
* @ContentElement("rs_column_stop", category="rs_columns")
*/
class ColumnStopController extends AbstractContentElementController
{
private ScopeMatcher $scopeMatcher;

public function __construct(ScopeMatcher $scopeMatcher)
{
$this->scopeMatcher = $scopeMatcher;
}

protected function getResponse(Template $template, ContentModel $model, Request $request): ?Response
{
if ($this->scopeMatcher->isBackendRequest($request)) {
$backendTemplate = new BackendTemplate('be_wildcard');
return new Response($backendTemplate->parse());
}

$parentKey = ($model->ptable ?: 'tl_article') . '__' . $model->pid;

if (isset($GLOBALS['TL_RS_COLUMNS'][$parentKey]) && !$GLOBALS['TL_RS_COLUMNS'][$parentKey]['active']) {
$GLOBALS['TL_RS_COLUMNS'][$parentKey]['active'] = true;
}
else {
trigger_error('Missing column start element before column stop element ID ' . $model->id . '.', E_USER_WARNING);
}

return new Response($template->parse());
}
}
Loading