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

[MessengerBundle] fix for standalone installation #2298

Merged
merged 2 commits into from
May 31, 2023
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
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();