Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .phpcq.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ Changelog
[Unreleased]
------------

### Deprecated

- Legacy content elements `bs_gridStart`, `bs_gridStop` and `bs_gridSeparator` are deprecated.
Use `bs_grid_wrapper` instead.

### Added

- Add support for nested fragments
- Bundle configuration option `enable_legacy_elements` (default: `true`) to disable legacy content elements.

3.0.5 (2025-03-02)
------------------

Expand Down
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ This extension provides Bootstrap 5 grid tools for Contao CMS.
Features
--------

- Manage grid definition in your theme settings
- Content elements
- Form elements
- Grid module
- Import/Export with your theme settings

- Manage grid definition in your theme settings
- Content elements
- Form elements
- Grid module
- Import/Export with your theme settings

Changelog
---------
Expand All @@ -32,7 +31,6 @@ Requirements
- PHP ^8.1
- Contao ^4.13 || ^5.3


Install
-------

Expand Down Expand Up @@ -73,3 +71,34 @@ class AppKernel
}

```

Migration
---------

To automatically migrate your grid from Start- and Stop-Wrappers to nested fragments, you have to enable the migration
via the bundle configuration. Create or extend the file `config/packages/contao_bootstrap_grid.yaml` in your Symfony
application:

```yaml
contao_bootstrap_grid:
enable_wrapper_migration: true
```

Afterwards you can run the migration in the Contao Manager or via CLI:

```bash
$ php vendor/bin/contao-console contao:migrate
```

Deprecated
----------

The legacy content elements `bs_gridStart`, `bs_gridStop` and `bs_gridSeparator` are deprecated and will be removed in
a future major version. Use `bs_grid_wrapper` instead.

To disable the legacy elements now, set the following configuration:

```yaml
contao_bootstrap_grid:
enable_legacy_elements: false
```
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<directory name="src"/>
<ignoreFiles>
<file name="src/ContaoBootstrapGridComponent.php"/>
<file name="src/DependencyInjection/Configuration.php"/>
</ignoreFiles>
</projectFiles>

Expand Down
25 changes: 24 additions & 1 deletion src/Component/ContentElement/GridSeparatorElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

/** @ContentElement("bs_gridSeparator", category="bs_grid", template="ce_bs_gridSeparator") */
use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;

/**
* @deprecated Use GridWrapperElementController with bs_grid_wrapper instead.
* Will be removed in a future major version.
*
* @ContentElement("bs_gridSeparator", category="bs_grid", template="ce_bs_gridSeparator")
*/
final class GridSeparatorElementController extends AbstractGridElementController
{
public function __construct(
Expand All @@ -34,6 +44,15 @@ public function __construct(
TranslatorInterface $translator,
private readonly RepositoryManager $repositories,
) {
trigger_error(
sprintf(
'Content element "%s" is deprecated. Use "%s" instead. Will be removed in a future major version.',
'bs_gridSeparator',
'bs_grid_wrapper',
),
E_USER_DEPRECATED,
);

parent::__construct(
$templateRenderer,
$scopeMatcher,
Expand Down Expand Up @@ -110,6 +129,10 @@ protected function getIterator(ContentModel $model): GridIterator|null
*/
protected function getParent(ContentModel $model): ContentModel|null
{
if ($model->ptable === 'tl_content') {
return $this->repositories->getRepository(ContentModel::class)->find($model->pid);
}

return $this->repositories->getRepository(ContentModel::class)->find((int) $model->bs_grid_parent);
}
}
48 changes: 47 additions & 1 deletion src/Component/ContentElement/GridStartElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,63 @@
namespace ContaoBootstrap\Grid\Component\ContentElement;

use Contao\ContentModel;
use Contao\CoreBundle\Security\Authentication\Token\TokenChecker;
use Contao\CoreBundle\ServiceAnnotation\ContentElement;
use Contao\Model;
use ContaoBootstrap\Core\Helper\ColorRotate;
use ContaoBootstrap\Grid\Exception\GridNotFound;
use ContaoBootstrap\Grid\GridIterator;
use ContaoBootstrap\Grid\GridProvider;
use Netzmacht\Contao\Toolkit\Response\ResponseTagger;
use Netzmacht\Contao\Toolkit\Routing\RequestScopeMatcher;
use Netzmacht\Contao\Toolkit\View\Template\TemplateRenderer;
use Override;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

/** @ContentElement("bs_gridStart", category="bs_grid", template="ce_bs_gridStart") */
use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;

/**
* @deprecated Use GridWrapperElementController with bs_grid_wrapper instead.
* Will be removed in a future major version.
*
* @ContentElement("bs_gridStart", category="bs_grid", template="ce_bs_gridStart")
*/
final class GridStartElementController extends AbstractGridElementController
{
public function __construct(
TemplateRenderer $templateRenderer,
RequestScopeMatcher $scopeMatcher,
ResponseTagger $responseTagger,
TokenChecker $tokenChecker,
GridProvider $gridProvider,
ColorRotate $colorRotate,
TranslatorInterface $translator,
) {
trigger_error(
sprintf(
'Content element "%s" is deprecated. Use "%s" instead. Will be removed in a future major version.',
'bs_gridStart',
'bs_grid_wrapper',
),
E_USER_DEPRECATED,
);

parent::__construct(
$templateRenderer,
$scopeMatcher,
$responseTagger,
$tokenChecker,
$gridProvider,
$colorRotate,
$translator,
);
}

/** {@inheritDoc} */
#[Override]
protected function preGenerate(
Expand Down
21 changes: 20 additions & 1 deletion src/Component/ContentElement/GridStopElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

/** @ContentElement("bs_gridStop", category="bs_grid", template="ce_bs_gridStop") */
use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;

/**
* @deprecated Use GridWrapperElementController with bs_grid_wrapper instead.
* Will be removed in a future major version.
*
* @ContentElement("bs_gridStop", category="bs_grid", template="ce_bs_gridStop")
*/
final class GridStopElementController extends AbstractGridElementController
{
public function __construct(
Expand All @@ -34,6 +44,15 @@ public function __construct(
TranslatorInterface $translator,
private readonly RepositoryManager $repositories,
) {
trigger_error(
sprintf(
'Content element "%s" is deprecated. Use "%s" instead. Will be removed in a future major version.',
'bs_gridStop',
'bs_grid_wrapper',
),
E_USER_DEPRECATED,
);

parent::__construct(
$templateRenderer,
$scopeMatcher,
Expand Down
14 changes: 10 additions & 4 deletions src/Component/ContentElement/GridWrapperElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ public function __construct(
#[Override]
protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response
{
$template->iterator = $this->getIterator($model);
$template->name = $model->bs_grid_name;
$template->color = $this->colorRotate->getColor('ce:' . $model->id);
$template->isBackend = $this->isBackendScope($request);
if ($this->isBackendScope($request)) {
$template->setName('backend/grid_wildcard');

$template->set('title', $model->bs_grid_name);
$template->set('color', $this->colorRotate->getColor('ce:' . $model->id));

return $template->getResponse();
}

$template->set('iterator', $this->getIterator($model));

return $template->getResponse();
}
Expand Down
30 changes: 30 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace ContaoBootstrap\Grid\DependencyInjection;

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

final class Configuration implements ConfigurationInterface
{
#[Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('contao_bootstrap_grid');

$treeBuilder->getRootNode()
->children()
->booleanNode('enable_wrapper_migration')
->defaultFalse()
->end()
->booleanNode('enable_legacy_elements')
->defaultTrue()
->end()
->end();

return $treeBuilder;
}
}
14 changes: 14 additions & 0 deletions src/DependencyInjection/ContaoBootstrapGridExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ final class ContaoBootstrapGridExtension extends Extension
#[Override]
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter(
'contao_bootstrap.grid.enable_wrapper_migration',
$config['enable_wrapper_migration'],
);

$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config'),
Expand All @@ -26,5 +34,11 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('config.yaml');
$loader->load('services.yaml');
$loader->load('listeners.yaml');

if (! $config['enable_legacy_elements']) {
return;
}

$loader->load('legacy.yaml');
}
}
17 changes: 17 additions & 0 deletions src/Listener/Dca/ContentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Contao\Config;
use Contao\ContentModel;
use Contao\Controller;
use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Image\ImageSizes;
use Contao\Database\Result;
Expand Down Expand Up @@ -70,6 +71,22 @@ public function initializeDca(): void
];
}

public function updatePaletteOnNestedParent(DataContainer $dataContainer): void
{
$input = $this->framework->getAdapter(Input::class);
$currentRecord = $dataContainer->getCurrentRecord();

if ($input->get('act') !== 'edit' || $currentRecord === null) {
return;
}

if ($currentRecord['type'] !== 'bs_gridSeparator' || $currentRecord['ptable'] !== 'tl_content') {
return;
}

PaletteManipulator::create()->removeField('bs_grid_parent')->applyToPalette('bs_gridSeparator', 'tl_content');
}

/**
* Get all grid parent options.
*
Expand Down
Loading