Skip to content

Commit

Permalink
Merge pull request #2298 from dpfaffenbauer/messenger-standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed May 31, 2023
2 parents 8eb31ee + 3e6ef05 commit 37a9d60
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function load(array $configs, ContainerBuilder $container): void
if (!array_key_exists('CoreShopCoreBundle', $bundles)) {
$loader->load('services/menu.yml');
}
else {
$loader->load('services/resource.yml');
}

$this->registerPimcoreResources('coreshop', $config['pimcore_admin'], $container);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@
use Pimcore\Event\BundleManager\PathsEvent;
use Pimcore\Event\BundleManagerEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;

final class AdminJavascriptListener implements EventSubscriberInterface
{
public function __construct(
private RouterInterface $router,
) {
}

public static function getSubscribedEvents(): array
{
return [
Expand All @@ -41,7 +35,7 @@ public function getAdminJavascript(PathsEvent $event): void
{
$event->setPaths(
array_merge($event->getPaths(), [
$this->router->generate('coreshop_menu', ['type' => 'coreshop.messenger']),
'/bundles/coreshopmessenger/pimcore/js/resource.js',
]),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

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

namespace CoreShop\Bundle\MessengerBundle\EventListener;

use Pimcore\Event\BundleManager\PathsEvent;
use Pimcore\Event\BundleManagerEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;

final class StandaloneAdminJavascriptListener implements EventSubscriberInterface
{
public function __construct(
private RouterInterface $router,
) {
}

public static function getSubscribedEvents(): array
{
return [
BundleManagerEvents::JS_PATHS => 'getAdminJavascript',
];
}

public function getAdminJavascript(PathsEvent $event): void
{
$event->setPaths(
array_merge($event->getPaths(), [
$this->router->generate('coreshop_menu', ['type' => 'coreshop.messenger']),
'/bundles/coreshopmessenger/pimcore/js/resource_standalone.js',
]),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
core_shop_messenger:
pimcore_admin:
js:
resource: '/bundles/coreshopmessenger/pimcore/js/resource.js'
list: '/bundles/coreshopmessenger/pimcore/js/list.js'
css:
index: '/bundles/coreshopmessenger/pimcore/css/messenger.css'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
tags:
- { name: 'coreshop.menu', type: messenger, menu: messenger }

CoreShop\Bundle\MessengerBundle\EventListener\AdminJavascriptListener:
CoreShop\Bundle\MessengerBundle\EventListener\StandaloneAdminJavascriptListener:
arguments:
- '@router'
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
public: true

CoreShop\Bundle\MessengerBundle\EventListener\AdminJavascriptListener:
tags:
- { name: kernel.event_subscriber }
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,27 @@

pimcore.registerNS('coreshop.messenger.resource');

if (coreshop.resource !== undefined) {
coreshop.messenger.resource = Class.create(coreshop.resource, {
initialize: function () {
coreshop.broker.fireEvent('resource.register', 'coreshop.messenger', this);
},

openResource: function(item) {
if (item === 'list') {
this.openList();
}
},

openList: function() {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
}
catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});

coreshop.broker.addListener('pimcore.ready', function() {
new coreshop.messenger.resource();
});
} else {
coreshop.messenger.resource = Class.create(pimcore.plugin.admin, {
initialize: function () {
var me = this;

document.addEventListener(pimcore.events.pimcoreReady, (e) => {
if (coreshop.menu.coreshop.messenger) {
new coreshop.menu.coreshop.messenger();
}
});

document.addEventListener(coreshop.events.menu.open, (e) => {
var item = e.detail.item;
var type = e.detail.type;

if (type === 'coreshop.messenger' && item.attributes.function === 'list') {
me.openList();
}
});
},

openList: function () {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
} catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});
coreshop.messenger.resource = Class.create(coreshop.resource, {
initialize: function () {
coreshop.broker.fireEvent('resource.register', 'coreshop.messenger', this);
},

openResource: function(item) {
if (item === 'list') {
this.openList();
}
},

openList: function() {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
}
catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});

coreshop.broker.addListener('pimcore.ready', function() {
new coreshop.messenger.resource();
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/*
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

pimcore.registerNS('coreshop.messenger.resource');

coreshop.messenger.resource = Class.create(pimcore.plugin.admin, {
initialize: function () {
var me = this;

document.addEventListener(pimcore.events.pimcoreReady, (e) => {
if (coreshop.menu.coreshop.messenger) {
new coreshop.menu.coreshop.messenger();
}
});

document.addEventListener(coreshop.events.menu.open, (e) => {
var item = e.detail.item;
var type = e.detail.type;

if (type === 'coreshop.messenger' && item.attributes.function === 'list') {
me.openList();
}
});
},

openList: function () {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
} catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});
new coreshop.messenger.resource();

0 comments on commit 37a9d60

Please sign in to comment.