Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Psdp 327] allow adding another element in perspective tree in perspective editor #148

Merged
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
37 changes: 26 additions & 11 deletions src/Controller/PerspectiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
namespace Pimcore\Bundle\PerspectiveEditorBundle\Controller;

use Pimcore\Bundle\AdminBundle\Security\CsrfProtectionHandler;
use Pimcore\Bundle\PerspectiveEditorBundle\Event\ElementTree\IconEvents;
use Pimcore\Bundle\PerspectiveEditorBundle\Event\ElementTree\Model\IconAddEvent;
use Pimcore\Bundle\PerspectiveEditorBundle\PimcorePerspectiveEditorBundle;
use Pimcore\Bundle\PerspectiveEditorBundle\Services\PerspectiveAccessor;
use Pimcore\Bundle\PerspectiveEditorBundle\Services\TreeHelper;
Expand All @@ -24,6 +26,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
Expand All @@ -35,7 +38,7 @@ class PerspectiveController extends UserAwareController
{
protected $disabledCssClass = 'pimcore_tree_node_disabled';

public function __construct(protected TranslatorInterface $translator)
public function __construct(protected TranslatorInterface $translator, protected EventDispatcherInterface $eventDispatcher)
{
}

Expand Down Expand Up @@ -275,24 +278,17 @@ protected function buildElementTree(TreeHelper $treeHelper, $config, $position =
return [];
}
$disabledClass = $config['writeable'] ? '' : $this->disabledCssClass;

$treeIcons = [
'documents' => 'pimcore_icon_document',
'assets' => 'pimcore_icon_asset',
'objects' => 'pimcore_icon_object',
'customview' => 'pimcore_icon_custom_views'
];

$elementTreeIcons = $this->getElementTreeIcons();
$tree = [];
foreach ($config['elementTree'] as $element) {
if ($position === ($element['position'] ?? 'left')) {
$tree[] = [
'id' => $treeHelper->createUuid(),
'text' => $element['type'],
'text' => preg_replace("/[\-_]/", ' ', $element['type']),
'type' => 'elementTreeElement',
'leaf' => true,
'allowDrag' => true,
'iconCls' => $treeIcons[$element['type']],
'iconCls' => $elementTreeIcons[$element['type']] ?? '',
'config' => $element,
'cls' => $disabledClass,
'writeable' => $config['writeable'],
Expand All @@ -307,6 +303,25 @@ protected function buildElementTree(TreeHelper $treeHelper, $config, $position =
return $tree;
}

/**
* get All Icons related to perspective element tree
*
* @return array
*/
private function getElementTreeIcons(): array
{
$elementTreeIcons = [
'documents' => 'pimcore_icon_document',
'assets' => 'pimcore_icon_asset',
'objects' => 'pimcore_icon_object',
'customview' => 'pimcore_icon_custom_views'
];
$elementTreeIconAddEvent = new IconAddEvent($elementTreeIcons);
$this->eventDispatcher->dispatch($elementTreeIconAddEvent, IconEvents::ADD_ELEMENT_TREE_ICON);

return $elementTreeIconAddEvent->getElementTreeIcons();
}

/**
* @param array $config
*
Expand Down
24 changes: 24 additions & 0 deletions src/Event/ElementTree/IconEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\PerspectiveEditorBundle\Event\ElementTree;

final class IconEvents
{
/**
* @var string
*/
public const ADD_ELEMENT_TREE_ICON = 'pimcore.perspectiveEditor.elementTreeIcon.add';
}
34 changes: 34 additions & 0 deletions src/Event/ElementTree/Model/IconAddEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\PerspectiveEditorBundle\Event\ElementTree\Model;

class IconAddEvent
{
public function __construct(
private array $elementTrees
) {
}

public function getElementTreeIcons(): array
{
return $this->elementTrees;
}

public function setElementTreeIcons(array $elementTrees): void
{
$this->elementTrees = $elementTrees;
}
}
Loading