Skip to content
Closed
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
12 changes: 6 additions & 6 deletions .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ jobs:
fail-fast: false
matrix:
include:
- name: '8.2 prefer-lowest'
php: '8.2'
phpcq_install: 'update'
phpcq_flags: '--exit-0'
composer_install: 'update --prefer-lowest'
- name: '8.2'
php: '8.2'
phpcq_install: 'update'
Expand All @@ -34,6 +29,11 @@ jobs:
phpcq_install: 'update'
phpcq_flags: ''
composer_install: 'update'
- name: '8.5'
php: '8.5'
phpcq_install: 'update'
phpcq_flags: ''
composer_install: 'update'
steps:
- name: PHP ${{ matrix.php }} Pull source
uses: actions/checkout@v6
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
run: ./vendor/bin/phpcq run -v -o github-action -o default ${{ matrix.phpcq_flags }}

- name: PHP ${{ matrix.php }} Upload build directory to artifact
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
if: ${{ success() }} || ${{ failure() }}
with:
name: phpcq-builds-php-${{ matrix.php }}
Expand Down
2 changes: 1 addition & 1 deletion .phpcq.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions .phpcq.yaml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
phpcq:
repositories:
- 'https://phpcq.github.io/repository/repository.json'
- vendor/netzmacht/phpspec-phpcq-plugin/repository.json
directories:
- src
artifact: .phpcq/build
Expand All @@ -11,7 +10,7 @@ phpcq:
signed: false
requirements:
composer:
doctrine/coding-standard: ^13.0
doctrine/coding-standard: ^14.0
composer-normalize:
version: ^1.0
signed: false
Expand All @@ -34,13 +33,15 @@ phpcq:
version: ^1.0
signed: false
trusted-keys:
- 6659B17090D6C5D3
- C00543248C87FB13
- 033E5F8D801A2F8D
- D2CCAC42F6295E7D
- 4AA394086372C20A
- 9093F8B32E4815AA
- 8A03EA3B385DBAA1
- 12CE0F1D262429A5
- 99BF4D9A33D65E1E
- 31C7E470E2138192
- 5E6DDE998AB73B8E
- A978220305CD5C32
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Changelog
[Unreleased]
------------

### Added

- Add support for nested fragments

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

Expand Down
19 changes: 12 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,10 @@ class AppKernel
}

```

Migration
-------

To automatically migrate your grid from Start- and Stop-Wrappers to nested fragments. You have to enbale the Migration
by adding `BS_GRID_WRAPPER_MIGRATION=true` parameter to your .env.local. Afterwards you can run the migration in the
contao manager over by cli.
22 changes: 10 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,26 @@
"source": "https://github.com/contao-bootstrap/grid"
},
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-dom": "*",
"ext-pdo": "*",
"contao-bootstrap/core": "^3.0",
"contao-community-alliance/meta-palettes": "^2.0",
"contao/core-bundle": "^4.13 || ^5.3",
"contao/core-bundle": "^5.3",
"doctrine/dbal": "^3.4",
"mvo/contao-group-widget": "^1.4",
"netzmacht/contao-toolkit": "^3.8 || ^4.0",
"symfony/config": "^5.4 || ^6.4 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
"symfony/http-foundation": "^5.4 || ^6.4 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
"symfony/routing": "^5.4 || ^6.4 || ^7.0",
"symfony/security-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/security-core": "^5.4 || ^6.4 || ^7.0",
"symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0"
"symfony/config": "^6.4 || ^7.4",
"symfony/dependency-injection": "^6.4 || ^7.4",
"symfony/http-foundation": "^6.4 || ^7.4",
"symfony/http-kernel": "^6.4 || ^7.4",
"symfony/routing": "^6.4 || ^7.4",
"symfony/security-core": "^6.4 || ^7.4",
"symfony/translation-contracts": "^3.0"
},
"require-dev": {
"contao/manager-plugin": "^2.1",
"contao/news-bundle": "^4.13 || ^5.3",
"netzmacht/phpspec-phpcq-plugin": "@dev",
"contao/news-bundle": "^5.3",
"phpcq/runner-bootstrap": "@dev"
},
"conflict": {
Expand Down
6 changes: 1 addition & 5 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<arg name="colors"/>

<!-- Required for the SlevomatCodingStandard which utilizes composer dependencies -->
<autoload>vendor/autoload.php</autoload>
<autoload>.phpcq/plugins/doctrine-coding-standard/vendor/autoload.php</autoload>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>
Expand All @@ -30,8 +30,4 @@
</properties>
<exclude-pattern>src/Resources/contao/languages/*</exclude-pattern>
</rule>

<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>spec/.*\.php</exclude-pattern>
</rule>
</ruleset>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<class name="Contao\ContentModel"/>
<class name="Contao\Database\Result"/>
<class name="Contao\FormFieldModel"/>
<class name="Contao\CoreBundle\Twig\FragmentTemplate"/>
<class name="Contao\BackendTemplate"/>
<class name="Contao\Model"/>
<class name="Contao\ModuleModel"/>
<class name="Contao\ModuleNews"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function getIterator(ContentModel $model): GridIterator|null

if ($parent) {
try {
$iterator = $provider->getIterator('ce:' . $parent->id, (int) $parent->bs_grid);
$iterator = $provider->getIterator('ce:' . $parent->id, (int)$parent->bs_grid);
$this->tagResponse('contao.db.tl_bs_grid.' . $parent->bs_grid);

return $iterator;
Expand All @@ -110,6 +110,10 @@ protected function getIterator(ContentModel $model): GridIterator|null
*/
protected function getParent(ContentModel $model): ContentModel|null
{
return $this->repositories->getRepository(ContentModel::class)->find((int) $model->bs_grid_parent);
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);
}
}
58 changes: 58 additions & 0 deletions src/Component/ContentElement/GridWrapperElementController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace ContaoBootstrap\Grid\Component\ContentElement;

use Contao\ContentModel;
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController;
use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement;
use Contao\CoreBundle\Twig\FragmentTemplate;
use ContaoBootstrap\Core\Helper\ColorRotate;
use ContaoBootstrap\Grid\Exception\GridNotFound;
use ContaoBootstrap\Grid\GridIterator;
use ContaoBootstrap\Grid\GridProvider;
use Override;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/** @psalm-suppress PropertyNotSetInConstructor */
#[AsContentElement('bs_grid_wrapper', 'bs_grid', nestedFragments: true)]
final class GridWrapperElementController extends AbstractContentElementController
{
public function __construct(
private readonly GridProvider $provider,
private readonly ColorRotate $colorRotate,
) {
}

#[Override]
protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response
{
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();
}

protected function getIterator(ContentModel $model): GridIterator|null
{
try {
$iterator = $this->provider->getIterator('ce:' . $model->id, (int)$model->bs_grid);
$this->tagResponse('contao.db.tl_bs_grid.' . $model->bs_grid);

return $iterator;
} catch (GridNotFound) {
// Do nothing. In backend view an error is shown anyway.
return null;
}
}
}
31 changes: 24 additions & 7 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 All @@ -18,9 +19,9 @@
use ContaoBootstrap\Core\Environment;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Override;
use stdClass;

use function sprintf;

use stdClass;
use function time;

/**
Expand All @@ -31,10 +32,10 @@
final class ContentListener extends AbstractWrapperDcaListener
{
/**
* @param Environment $environment Bootstrap environment.
* @param ContaoFramework $framework Contao framework.
* @param ImageSizes $imageSizes Image sizes.
* @param BackendUser $user Contao backend user.
* @param Environment $environment Bootstrap environment.
* @param ContaoFramework $framework Contao framework.
* @param ImageSizes $imageSizes Image sizes.
* @param BackendUser $user Contao backend user.
*/
public function __construct(
Environment $environment,
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 Expand Up @@ -123,7 +140,7 @@ public function getGalleryTemplates(): array
/**
* Dynamically add flags to the "multiSRC" field.
*
* @param mixed $value Given value.
* @param mixed $value Given value.
* @param DataContainer $dataContainer Data Container driver.
*
* @SuppressWarnings(PHPMD.Superglobals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Contao\Model\Collection;
use Doctrine\DBAL\Connection;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Netzmacht\Contao\Toolkit\Dca\Definition;
use Netzmacht\Contao\Toolkit\Dca\DcaManager;
use Netzmacht\Contao\Toolkit\Dca\Definition;

use function array_unique;
use function time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use ContaoBootstrap\Grid\Listener\Dca\ParentFixContentParentRelationsListener;
use Netzmacht\Contao\Toolkit\Assertion\AssertionFailed;
use Netzmacht\Contao\Toolkit\Dca\Definition;
use Netzmacht\Contao\Toolkit\Dca\DcaManager;
use Netzmacht\Contao\Toolkit\Dca\Definition;

use function in_array;
use function is_array;
Expand Down
Loading