Skip to content

Commit

Permalink
added warning when database rows missing, fixes some deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Nov 2, 2021
1 parent c64a37d commit dc866e1
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [1.8.0] - 2021-11-02
- Added: warning when database rows are missing
- Fixed: some deprecations

## [1.7.1] - 2021-09-29
- Fixed: another "Warning: Invalid argument supplied for foreach()"

Expand Down
9 changes: 5 additions & 4 deletions src/Backend/ColumnSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace HeimrichHannot\SubColumnsBootstrapBundle\Backend;

use Contao\StringUtil;
use HeimrichHannot\SubColumnsBootstrapBundle\Model\ColumnsetModel;
use HeimrichHannot\SubColumnsBootstrapBundle\SubColumnsBootstrapBundle;

Expand Down Expand Up @@ -35,18 +36,18 @@ public static function prepareContainer($id)
return null;
}

$sizes = deserialize($model->sizes, true);
$sizes = StringUtil::deserialize($model->sizes, true);
$container = [];

foreach ($sizes as $size) {
$key = 'columnset_' . $size;
$columns = deserialize($model->{$key}, true);
$columns = StringUtil::deserialize($model->{$key}, true);

foreach ($columns as $index => $column) {
if (isset($container[$index][0])) {
$container[$index][0] .= ' ' . self::prepareSize($size, deserialize($column, true));
$container[$index][0] .= ' ' . self::prepareSize($size, StringUtil::deserialize($column, true));
} else {
$container[$index][0] .= self::prepareSize($size, deserialize($column, true));
$container[$index][0] .= self::prepareSize($size, StringUtil::deserialize($column, true));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Backend/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace HeimrichHannot\SubColumnsBootstrapBundle\Backend;


use Contao\Backend;
use Contao\DataContainer;
use Contao\System;

class Content extends \Backend
class Content extends Backend
{
public function createPalette(DataContainer $dc)
{
Expand Down
9 changes: 8 additions & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use Contao\ManagerPlugin\Config\ContainerBuilder;
use Contao\ManagerPlugin\Config\ExtensionPluginInterface;
use HeimrichHannot\UtilsBundle\Container\ContainerUtil;
use Symfony\Component\Config\Loader\LoaderInterface;

/**
* Class Plugin
*
* @package HeimrichHannot\SubColumnsBootstrapBundle\ContaoManager
*/
class Plugin implements BundlePluginInterface, ExtensionPluginInterface
class Plugin implements BundlePluginInterface, ExtensionPluginInterface, ConfigPluginInterface
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -44,4 +46,9 @@ public function getExtensionConfig($extensionName, array $extensionConfigs, Cont
__DIR__.'/../Resources/config/config_encore.yml'
);
}

public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig)
{
$loader->load("@SubColumnsBootstrapBundle/Resources/config/services.yml");
}
}
58 changes: 58 additions & 0 deletions src/DataContainer/ColumnsetContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace HeimrichHannot\SubColumnsBootstrapBundle\DataContainer;

use Contao\Config;
use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\Input;
use Contao\Message;
use Doctrine\DBAL\Connection;
use HeimrichHannot\UtilsBundle\Util\Utils;
use Symfony\Component\HttpFoundation\RequestStack;

class ColumnsetContainer
{
/**
* @var Connection
*/
private $connection;
/**
* @var RequestStack
*/
private $requestStack;
/**
* @var ScopeMatcher
*/
private $scopeMatcher;

public function __construct(Connection $connection, RequestStack $requestStack, ScopeMatcher $scopeMatcher)
{
$this->connection = $connection;
$this->requestStack = $requestStack;
$this->scopeMatcher = $scopeMatcher;
}


public function onLoadCallback($dc): void
{
$request = $this->requestStack->getCurrentRequest();
if (!$request || !$this->scopeMatcher->isBackendRequest($request) || 'edit' !== $request->get('act')) {
return;
}

$sizes = $GLOBALS['TL_SUBCL'][Config::get('subcolumns')]['sizes'] ?? null;
if (!$sizes) {
return;
}

$tableColumns = $this->connection->getSchemaManager()->listTableColumns('tl_columnset');

foreach ($sizes as $size)
{
if (!array_key_exists('columnset_'.strtolower($size), $tableColumns)) {
Message::addError($GLOBALS['TL_LANG']['ERR']['huhSubColMissingTableRow']);
return;
}
}
}
}
8 changes: 8 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true

HeimrichHannot\SubColumnsBootstrapBundle\:
resource: '../../{DataContainer}/*'
public: true
3 changes: 3 additions & 0 deletions src/Resources/contao/dca/tl_columnset.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

use HeimrichHannot\SubColumnsBootstrapBundle\DataContainer\ColumnsetContainer;

$GLOBALS['TL_DCA']['tl_columnset'] = [
'config' => [
'dataContainer' => 'Table',
'enableVersioning' => true,
'onload_callback' => [
['HeimrichHannot\SubColumnsBootstrapBundle\Backend\ColumnSet', 'appendColumnSizesToPalette'],
[ColumnsetContainer::class, 'onLoadCallback']
],
'sql' => [
'keys' => [
Expand Down
10 changes: 9 additions & 1 deletion src/Resources/contao/languages/de/default.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<?php

$GLOBALS['TL_LANG']['CTE']['colsetPart'][0] = 'Spaltenset Trennelement';
/*
* Content Elements
*/
$GLOBALS['TL_LANG']['CTE']['colsetPart'][0] = 'Spaltenset Trennelement';

/*
* Errors
*/
$GLOBALS['TL_LANG']['ERR']['huhSubColMissingTableRow'] = 'Scheinbar wurde nach der Änderungen Subcolumns-Konfiguration die Datenbank noch nicht geupdated. Dies kann zu Fehlern beim Speichern der Konfiguration führen. Bitte updaten Sie die Datenbank, bevor Sie weitermachen.';
9 changes: 9 additions & 0 deletions src/Resources/contao/languages/en/default.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
<?php

/*
* Content Elements
*/
$GLOBALS['TL_LANG']['CTE']['colsetPart'][0] = 'Columnset divider element';

/*
* Errors
*/
$GLOBALS['TL_LANG']['ERR']['huhSubColMissingTableRow'] = 'The database seems to be not updated after changing the subcolumns configuration. This may lead to errors on saving. Please update the database before continuing.';

0 comments on commit dc866e1

Please sign in to comment.