-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add ArebrickOverviewController in Bundle
- Loading branch information
Showing
11 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
neusta_converter: | ||
converter: | ||
brick.converter: | ||
target: Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\BrickView | ||
populators: | ||
- Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPagePopulator | ||
properties: | ||
name: ~ | ||
id: ~ | ||
tags: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
neusta_pimcore_areabrick_config: | ||
resource: '@NeustaPimcoreAreabrickConfigBundle/Controller/Admin/' | ||
type: annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
imports: | ||
- { resource: packages/* } | ||
- { resource: pimcore/* } | ||
|
||
services: | ||
# default configuration for services in *this* file | ||
_defaults: | ||
# automatically injects dependencies in your services | ||
autowire: true | ||
# automatically registers your services as commands, event subscribers, etc. | ||
autoconfigure: true | ||
# this means you cannot fetch services directly from the container via $container->get() | ||
# if you need to do this, you can override this setting on individual services | ||
public: false | ||
|
||
Neusta\Pimcore\AreabrickConfigBundle\Controller\Admin\AreabrickOverviewController: | ||
class: Neusta\Pimcore\AreabrickConfigBundle\Controller\Admin\AreabrickOverviewController | ||
public: true | ||
arguments: | ||
$brickConverter: '@brick.converter' | ||
tags: [ 'controller.service_arguments' ] | ||
|
||
Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPagePopulator: ~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model; | ||
|
||
class BrickView | ||
{ | ||
public string $name; | ||
public string $id; | ||
|
||
/** @var array<string> */ | ||
public array $tags; | ||
|
||
/** @var array<mixed> */ | ||
public array $pageFullPaths; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator; | ||
|
||
use Neusta\ConverterBundle\Converter\Context\GenericContext; | ||
use Neusta\ConverterBundle\Populator; | ||
use Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\BrickView; | ||
use Pimcore\Db; | ||
use Pimcore\Extension\Document\Areabrick\AbstractAreabrick; | ||
use Pimcore\Model\Document\Page; | ||
|
||
/** | ||
* @implements Populator<AbstractAreabrick, BrickView, GenericContext> | ||
*/ | ||
class BrickPagePopulator implements Populator | ||
{ | ||
public function populate(object $target, object $source, ?object $ctx = null): void | ||
{ | ||
$editableUsages = Db::get()->fetchAllAssociative("SELECT DISTINCT documentId FROM documents_editables WHERE data LIKE '%" . $source->getId() . "%'"); | ||
$target->pageFullPaths = []; | ||
foreach (array_values($editableUsages) as $docId) { | ||
$page = Page::getById($docId['documentId']); | ||
$target->pageFullPaths[] = [ | ||
$page?->isPublished(), | ||
$page?->getFullPath(), | ||
]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\Controller\Admin; | ||
|
||
use Neusta\ConverterBundle\Converter; | ||
use Pimcore\Controller\UserAwareController; | ||
use Pimcore\Extension\Document\Areabrick\AreabrickManagerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
// Todo: check if this can't be accessed outside the admin context in Pimcore 11 | ||
final class AreabrickOverviewController extends UserAwareController | ||
{ | ||
public function __construct( | ||
private AreabrickManagerInterface $areabrickManager, | ||
private Converter $brickConverter, | ||
) { | ||
} | ||
|
||
#[Route('/admin/areabricks/list', name: 'areabrick_overview', methods: ['GET'])] | ||
public function defaultAction(Request $request): Response | ||
{ | ||
$ctx = null; | ||
|
||
$bricks = array_map( | ||
function ($item) use ($ctx) { | ||
return $this->brickConverter->convert($item, $ctx); | ||
}, | ||
$this->areabrickManager->getBricks() | ||
); | ||
|
||
return $this->render( | ||
'bricks/default.html.twig', | ||
[ | ||
'bricks' => $bricks, | ||
] | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/DependencyInjection/NeustaPimcoreAreabrickConfigExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\AreabrickConfigBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
|
||
class NeustaPimcoreAreabrickConfigExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new Loader\YamlFileLoader($container, new FileLocator(\dirname(__DIR__, 2) . '/config')); | ||
$loader->load('services.yaml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Example</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<style type="text/css"> | ||
table { | ||
background-color: #ffffff; | ||
border-collapse: collapse; | ||
border: none; | ||
} | ||
thead { | ||
background-color: #0096f3; | ||
} | ||
tfoot { | ||
background-color: #F7F1D4; | ||
font-size: 80%; | ||
border-top: 1px solid #999; | ||
} | ||
td, th { | ||
text-align: left; | ||
padding: 0.5em 1em; | ||
} | ||
</style> | ||
|
||
|
||
<div id="site"> | ||
<table id="logo"> | ||
<thead> | ||
<th>Name</th> | ||
<th>ID</th> | ||
<th>Tags</th> | ||
<th><strike>Unpublished</strike> Pages (using Brick)</th> | ||
</thead> | ||
{% for brick in bricks %} | ||
<tbody> | ||
<td>{{ brick.name }}</td> | ||
<td>{{ brick.id }}</td> | ||
<td> | ||
{% for tag in brick.tags %} | ||
{% if tag in brick.tags %} | ||
{{ tag }}, | ||
{% else %} | ||
<strikethrough>{{ tag }}</strikethrough>, | ||
{% endif %} | ||
{% endfor %} | ||
</td> | ||
<td> | ||
{% for fullPath in brick.pageFullPaths %} | ||
{% if fullPath[0] %} | ||
<a href="{{ fullPath[1] }}">{{ fullPath[1] }}</a>, | ||
{% else %} | ||
<strike>{{ fullPath[1] }}</strike> | ||
{% endif %} | ||
{% endfor %} | ||
</td> | ||
</tbody> | ||
{% endfor %} | ||
</table> | ||
</div> | ||
|
||
</body> | ||
</html> |