Skip to content

Commit

Permalink
EZP-28636: Universal Discovery Widget should have configurable root l…
Browse files Browse the repository at this point in the history
…ocation ID
  • Loading branch information
webhdx committed Dec 21, 2017
1 parent bfff82b commit 7382c8c
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser;
namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\Module;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
Expand All @@ -24,7 +24,7 @@
* limit: 10
* ```
*/
class SubitemsModule extends AbstractParser
class Subitems extends AbstractParser
{
/**
* Adds semantic configuration definition.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\Module;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* Configuration parser for UDW module.
*/
class UniversalDiscoveryWidget extends AbstractParser
{
/**
* Adds semantic configuration definition.
*
* @param NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
{
$nodeBuilder
->arrayNode('universal_discovery_widget_module')
->info('UDW module configuration')
->children()
->scalarNode('default_location_id')->isRequired()->end()
->end()
->end();
}

/**
* {@inheritdoc}
*/
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
{
if (empty($scopeSettings['universal_discovery_widget_module'])) {
return;
}

$settings = $scopeSettings['universal_discovery_widget_module'];

if (!isset($settings['default_location_id']) || empty($settings['default_location_id'])) {
return;
}

$contextualizer->setContextualParameter(
'universal_discovery_widget_module.default_location_id',
$currentScope,
$settings['default_location_id']
);
}
}
5 changes: 3 additions & 2 deletions src/bundle/EzPlatformAdminUiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\UiConfigProviderPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\ValueObjectVisitorPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\LocationIds;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\Module;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\Pagination;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubitemsModule;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand All @@ -27,7 +27,8 @@ public function build(ContainerBuilder $container)
/** @var EzPublishCoreExtension $core */
$core = $container->getExtension('ezpublish');
$core->addConfigParser(new LocationIds());
$core->addConfigParser(new SubitemsModule());
$core->addConfigParser(new Module\Subitems());
$core->addConfigParser(new Module\UniversalDiscoveryWidget());
$core->addConfigParser(new Pagination());
$core->addDefaultSettings(__DIR__ . '/Resources/config', ['ezplatform_default_settings.yml']);

Expand Down
3 changes: 3 additions & 0 deletions src/bundle/Resources/config/ezplatform_default_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ parameters:

# Subitems Module
ezsettings.default.subitems_module.limit: 10

# Universal Discovery Widget Module
ezsettings.default.universal_discovery_widget_module.default_location_id: 1
2 changes: 0 additions & 2 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ imports:
- { resource: services/controllers.yml }
- { resource: services/tabs.yml }
- { resource: services/menu.yml }
- { resource: services/application_config.yml }
- { resource: services/type_extensions.yml }
- { resource: services/pagination.yml }
- { resource: services/ui_config.yml }
- { resource: services/components.yml }
Expand Down
8 changes: 0 additions & 8 deletions src/bundle/Resources/config/services/application_config.yml

This file was deleted.

5 changes: 0 additions & 5 deletions src/bundle/Resources/config/services/type_extensions.yml

This file was deleted.

10 changes: 10 additions & 0 deletions src/bundle/Resources/config/services/ui_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ services:
autoconfigure: true
public: false

EzSystems\EzPlatformAdminUiBundle\Templating\Twig\UiConfigExtension:
public: true

EzSystems\EzPlatformAdminUi\UI\Config\Aggregator:
public: true

EzSystems\EzPlatformAdminUi\UI\Config\Provider\ContentTypeMappings:
arguments:
$locationMappings: '%ezplatform.multifile_upload.location.mappings%'
Expand All @@ -23,3 +29,7 @@ services:
EzSystems\EzPlatformAdminUi\UI\Config\Provider\User:
tags:
- { name: ezplatform.admin_ui.config_provider, key: 'user' }

EzSystems\EzPlatformAdminUi\UI\Config\Provider\Module\UniversalDiscoveryWidget:
tags:
- { name: ezplatform.admin_ui.config_provider, key: 'universalDiscoveryWidget' }
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class EzEmbedDiscoverContentButton extends EzWidgetButton {
confirmLabel: 'Select content',
title: this.props.udwTitle,
multiple: false,
startingLocationId: '1',
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess},
canSelectContent: selectable,
}), udwContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class EzBtnLinkEdit extends Component {
confirmLabel: 'Select content',
title: 'Select content',
multiple: false,
startingLocationId: '1',
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess},
}), udwContainer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
onCancel: closeUDW,
confirmLabel: 'Add locations',
title: 'Choose locations',
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
multiple: true,
restInfo: {token, siteaccess}
}), udwContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
onConfirm: selectSubtreeConfirm.bind(this),
onCancel: closeUDW,
multiple: true,
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess}
}), udwContainer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ReactDOM.render(React.createElement(eZ.modules.UniversalDiscovery, {
onConfirm: onConfirm.bind(this, form),
onCancel,
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess}
}), udwContainer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ReactDOM.render(React.createElement(eZ.modules.UniversalDiscovery, {
onConfirm: onConfirm.bind(this, form),
onCancel,
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess}
}), udwContainer);
};
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/public/js/scripts/admin.trash.list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
onCancel,
confirmLabel: 'Restore',
title: 'Select a location to restore you content item(s)',
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess}
}), udwContainer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@
const trashBtn = fieldContainer.querySelector('.ez-relations__table-action--remove');
const isSingle = fieldContainer.classList.contains(CLASS_FIELD_SINGLE);
const selectedItemsLimit = isSingle ? 1 : parseInt(relationsContainer.dataset.limit, 10);
const startingLocationId = relationsContainer.dataset.defaultLocation !== '0' ?
parseInt(relationsContainer.dataset.defaultLocation, 10) : 1;
const startingLocationId = relationsContainer.dataset.defaultLocation !== '0'
? parseInt(relationsContainer.dataset.defaultLocation, 10)
: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId;
const allowedContentTypes = relationsContainer.dataset.allowedContentTypes.split(',').filter(item => item.length);
const closeUDW = () => udwContainer.innerHTML = '';
const renderRows = (items) => items.forEach((...args) => relationsContainer.insertAdjacentHTML('beforeend', renderRow(...args)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
confirmLabel: 'Add location',
title: 'Select location',
multiple: false,
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess}
}), udwContainer);
};
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/js/scripts/udw/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
confirmLabel: 'Swap location',
title: 'Select location to be swapped with',
multiple: false,
startingLocationId: parseInt(event.currentTarget.dataset.rootLocation, 10),
startingLocationId: window.eZ.adminUiConfig.universalDiscoveryWidget.startingLocationId,
restInfo: {token, siteaccess}
}), udwContainer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<tr>
<td>
{{ 'tab.locations.swap_with_another'|trans()|desc('Swap the content item at this location with another') }}
{{ form_widget(form.swap, {'attr': {'class': 'btn-outline-secondary btn--udw-swap ml-5', 'data-root-location': '1'}}) }}
{{ form_widget(form.swap, {'attr': {'class': 'btn-outline-secondary btn--udw-swap ml-5'}}) }}
{{ form_widget(form.current_location) }}
{{ form_widget(form.new_location) }}
</td>
Expand Down
19 changes: 15 additions & 4 deletions src/lib/Menu/ContentRightSidebarBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use InvalidArgumentException;
use JMS\TranslationBundle\Model\Message;
Expand All @@ -34,19 +35,25 @@ class ContentRightSidebarBuilder extends AbstractBuilder implements TranslationC
/** @var PermissionResolver */
private $permissionResolver;

/** @var ConfigResolverInterface */
private $configResolver;

/**
* @param PermissionResolver $permissionResolver
* @param MenuItemFactory $factory
* @param EventDispatcherInterface $eventDispatcher
* @param PermissionResolver $permissionResolver
* @param ConfigResolverInterface $configResolver
*/
public function __construct(
MenuItemFactory $factory,
EventDispatcherInterface $eventDispatcher,
PermissionResolver $permissionResolver
PermissionResolver $permissionResolver,
ConfigResolverInterface $configResolver
) {
parent::__construct($factory, $eventDispatcher);

$this->permissionResolver = $permissionResolver;
$this->configResolver = $configResolver;
}

/**
Expand Down Expand Up @@ -117,7 +124,9 @@ public function createStructure(array $options): ItemInterface
'extras' => ['icon' => 'move'],
'attributes' => [
'class' => 'btn--udw-move',
'data-root-location' => 1,
'data-root-location' => $this->configResolver->getParameter(
'universal_discovery_widget_module.default_location_id'
),
],
]
),
Expand All @@ -127,7 +136,9 @@ public function createStructure(array $options): ItemInterface
'extras' => ['icon' => 'copy'],
'attributes' => [
'class' => 'btn--udw-copy',
'data-root-location' => 1,
'data-root-location' => $this->configResolver->getParameter(
'universal_discovery_widget_module.default_location_id'
),
],
]
),
Expand Down
24 changes: 23 additions & 1 deletion src/lib/Menu/LeftSidebarBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
*/
namespace EzSystems\EzPlatformAdminUi\Menu;

use eZ\Publish\Core\MVC\ConfigResolverInterface;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use InvalidArgumentException;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* KnpMenuBundle Menu Builder service implementation for AdminUI left sidebar menu.
Expand All @@ -19,11 +21,29 @@
*/
class LeftSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
{
/** @var ConfigResolverInterface */
private $configResolver;

/* Menu items */
const ITEM__SEARCH = 'sidebar_left__search';
const ITEM__BROWSE = 'sidebar_left__browse';
const ITEM__TRASH = 'sidebar_left__trash';

/**
* @param MenuItemFactory $factory
* @param EventDispatcherInterface $eventDispatcher
* @param ConfigResolverInterface $configResolver
*/
public function __construct(
MenuItemFactory $factory,
EventDispatcherInterface $eventDispatcher,
ConfigResolverInterface $configResolver
) {
parent::__construct($factory, $eventDispatcher);

$this->configResolver = $configResolver;
}

/**
* @return string
*/
Expand Down Expand Up @@ -57,7 +77,9 @@ public function createStructure(array $options): ItemInterface
'extras' => ['icon' => 'browse'],
'attributes' => [
'class' => 'btn--udw-browse',
'data-starting-location-id' => 1,
'data-starting-location-id' => $this->configResolver->getParameter(
'universal_discovery_widget_module.default_location_id'
),
],
]
),
Expand Down
41 changes: 41 additions & 0 deletions src/lib/UI/Config/Provider/Module/UniversalDiscoveryWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\UI\Config\Provider\Module;

use eZ\Publish\Core\MVC\ConfigResolverInterface;
use EzSystems\EzPlatformAdminUi\UI\Config\ProviderInterface;

/**
* Provides information about current user with resolved profile picture.
*/
class UniversalDiscoveryWidget implements ProviderInterface
{
/** @var ConfigResolverInterface */
private $configResolver;

/**
* @param ConfigResolverInterface $configResolver
*/
public function __construct(
ConfigResolverInterface $configResolver
) {
$this->configResolver = $configResolver;
}

/**
* @return array
*/
public function getConfig(): array
{
/* config structure has to reflect UDW module's config structure */
return [
'startingLocationId' => $this->configResolver->getParameter(
'universal_discovery_widget_module.default_location_id'
),
];
}
}

0 comments on commit 7382c8c

Please sign in to comment.