Skip to content

Commit

Permalink
Merge branch 'hotfix/fix_delete_copy_button_ad_edit_all' into 'releas…
Browse files Browse the repository at this point in the history
…e/2.3.0'

Fix delete copy button at edit all

See merge request metamodels/core!384
  • Loading branch information
zonky2 committed Jan 15, 2025
2 parents 5095ce8 + ee295be commit c0b2fa7
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 62 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

/**
* This file is part of MetaModels/core.
*
* (c) 2012-2025 The MetaModels team.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package MetaModels/core
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2012-2025 The MetaModels team.
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

namespace MetaModels\CoreBundle\EventListener\DcGeneral\Table;

use ContaoCommunityAlliance\DcGeneral\Contao\RequestScopeDeterminator;
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetSelectModeButtonsEvent;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface;
use ContaoCommunityAlliance\DcGeneral\Event\AbstractEnvironmentAwareEvent;
use ContaoCommunityAlliance\DcGeneral\Event\AbstractModelAwareEvent;

use function array_key_exists;
use function in_array;

class SelectModeButtonsListener
{
public function __construct(
private readonly RequestScopeDeterminator $scopeDeterminator
) {
}

/**
* Delete copy button at edit all.
*
* @param GetSelectModeButtonsEvent $event The event.
*
* @return void
*/
public function handle(GetSelectModeButtonsEvent $event): void
{
if (!$this->wantToHandle($event)) {
return;
}

$buttons = $event->getButtons();
if (array_key_exists('copy', $buttons)) {
unset($buttons['copy']);
$event->setButtons($buttons);
}
}

/**
* Test if the event is for the correct table and in backend scope.
*
* @param AbstractEnvironmentAwareEvent $event The event to test.
*
* @return bool
*/
protected function wantToHandle(AbstractEnvironmentAwareEvent $event)
{
if (!$this->scopeDeterminator->currentScopeIsBackend()) {
return false;
}

$environment = $event->getEnvironment();
$dataDefinition = $environment->getDataDefinition();
assert($dataDefinition instanceof ContainerInterface);

if (
!in_array(
$dataDefinition->getName(),
[
'tl_metamodel',
'tl_metamodel_attribute',
'tl_metamodel_dca_sortgroup',
'tl_metamodel_dcasetting',
'tl_metamodel_dcasetting_condition',
'tl_metamodel_rendersetting',
'tl_metamodel_searchable_pages',
]
)
) {
return false;
}

if (
($event instanceof AbstractModelAwareEvent)
&& $dataDefinition->getName() !== $event->getModel()->getProviderName()
) {
return false;
}

return true;
}
}
9 changes: 9 additions & 0 deletions src/CoreBundle/Resources/config/dc-general/listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ services:
- name: kernel.event_listener
event: dc-general.view.contao2backend.get-operation-button
method: handle

MetaModels\CoreBundle\EventListener\DcGeneral\Table\SelectModeButtonsListener:
arguments:
- "@cca.dc-general.scope-matcher"
tags:
- name: kernel.event_listener
event: dc-general.view.contao2backend.get-select-mode-buttons
method: handle
priority: -100
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ services:
event: dc-general.view.contao2backend.encode-property-value-from-widget
method: handle

MetaModels\CoreBundle\EventListener\DcGeneral\Table\MetaModel\SelectModeButtonsListener:
arguments:
- "@cca.dc-general.scope-matcher"
tags:
- name: kernel.event_listener
event: dc-general.view.contao2backend.get-select-mode-buttons
method: handle
priority: -100

MetaModels\CoreBundle\EventListener\DcGeneral\Table\MetaModel\ModelSchemaManagerHintListener:
arguments:
- "@cca.dc-general.scope-matcher"
Expand Down

0 comments on commit c0b2fa7

Please sign in to comment.