Skip to content

Commit

Permalink
fix: phpstan
Browse files Browse the repository at this point in the history
feat: add deeplink to edit mode
  • Loading branch information
mike4git committed Sep 28, 2024
1 parent 27963f6 commit fe705d8
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 11 deletions.
2 changes: 2 additions & 0 deletions config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ neusta_converter:

pimcore_areabrick_config.page.converter:
target: Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Page
populators:
- Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPageEditModeUrlPopulator
properties:
published: ~
url: fullPath
3 changes: 3 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ services:
$brickConverter: '@pimcore_areabrick_config.brick.converter'
tags: [ 'controller.service_arguments' ]

Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPageEditModeUrlPopulator: ~

pimcore_areabrick_config.brick.page.populator:
class: Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPagePopulator
arguments:
$pageConverter: '@pimcore_areabrick_config.page.converter'


Neusta\Pimcore\AreabrickConfigBundle\EventListener\PimcoreAdminListener:
tags:
- { name: kernel.event_listener, event: pimcore.bundle_manager.paths.css, method: addCSSFiles }
Expand Down
2 changes: 2 additions & 0 deletions src/Bricks/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class Page
{
public string $name;
public bool $published = false;
public string $url;
public string $editModeUrl;
}
21 changes: 21 additions & 0 deletions src/Bricks/Populator/BrickPageEditModeUrlPopulator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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\Page;
use Pimcore\Model\Document\Page as PimcorePage;

/**
* @implements Populator<PimcorePage, Page, GenericContext|null>
*/
class BrickPageEditModeUrlPopulator implements Populator
{
public function populate(object $target, object $source, ?object $ctx = null): void
{
$target->editModeUrl = \sprintf('/admin/login/deeplink?document_%s_page', $source->getId());
}
}
5 changes: 2 additions & 3 deletions src/Controller/Admin/AreabrickOverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
use Neusta\ConverterBundle\Converter;
use Neusta\ConverterBundle\Converter\Context\GenericContext;
use Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Brick;
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController;
use Pimcore\Controller\FrontendController;
use Pimcore\Extension\Document\Areabrick\AreabrickInterface;
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 AdminAbstractController // UserAwareController
final class AreabrickOverviewController extends FrontendController // UserAwareController
{
/**
* @param Converter<AreabrickInterface, Brick, GenericContext|null> $brickConverter
Expand Down
14 changes: 8 additions & 6 deletions templates/bricks/additional_properties.html.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{# Additional Properties of Brick #}
{% if brick.additionalProperties is defined and brick.additionalProperties is not empty %}
<td>
{% for additionalProperty in brick.additionalProperties|default([]) %}
{% if additionalProperty is defined and additionalProperty.propertyValue is not empty %}
<li>{{ additionalProperty.propertyName }}:{{ additionalProperty.propertyValue }}</li>
{% endif %}
{% endfor %}
{% for additionalProperty in brick.additionalProperties|default([]) %}
{% if additionalProperty is defined and additionalProperty.propertyValue is not empty %}
<li>{{ additionalProperty.propertyName }}:{{ additionalProperty.propertyValue }}</li>
{% endif %}
{% endfor %}
</td>
{% else %}
{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.no_additional_properties'|trans }}
<td>
{{ 'neusta_pimcore_areabrick_config.areabricks.overview.table.no_additional_properties'|trans }}
</td>
{% endif %}
4 changes: 2 additions & 2 deletions templates/bricks/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
<td>
{% for page in brick.pages %}
{% if page.published %}
<li><a href="{{ page.url }}">{{ page.url }}</a></li>
<li><a href="{{ page.editModeUrl }}">{{ page.url }}</a> (<a href="{{ page.url }}">Frontend</a>)</li>
{% else %}
<li><strike>{{ page.url }}</strike></li>
<li style="text-decoration: line-through;"><a href="{{ page.editModeUrl }}">{{ page.url }}</a></li>
{% endif %}
{% endfor %}
</td>
Expand Down
43 changes: 43 additions & 0 deletions tests/Unit/Bricks/Populator/BrickPageEditModeUrlPopulatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace App\Tests\AreabrickConfigBundle\Bricks\Populator;

use Neusta\ConverterBundle\Populator;
use Neusta\Pimcore\AreabrickConfigBundle\Bricks\Model\Page;
use Neusta\Pimcore\AreabrickConfigBundle\Bricks\Populator\BrickPageEditModeUrlPopulator;
use PHPUnit\Framework\TestCase;
use Pimcore\Model\Document\Page as PimcorePage;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;

class BrickPageEditModeUrlPopulatorTest extends TestCase
{
use ProphecyTrait;

private Populator $populator;

/** @var ObjectProphecy<PimcorePage> */
private $source;

private Page $target;

protected function setUp(): void
{
$this->source = $this->prophesize(PimcorePage::class);
$this->source->getId()->willReturn(123);

$this->populator = new BrickPageEditModeUrlPopulator();
}

/**
* @test
*/
public function populate_regular_case(): void
{
$this->target = new Page();

$this->populator->populate($this->target, $this->source->reveal());

self::assertEquals('/admin/login/deeplink?document_123_page', $this->target->editModeUrl);
}
}

0 comments on commit fe705d8

Please sign in to comment.