-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/fix_delete_copy_button_ad_edit_all' into 'releas…
…e/2.3.0' Fix delete copy button at edit all See merge request metamodels/core!384
- Loading branch information
Showing
4 changed files
with
110 additions
and
62 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
src/CoreBundle/EventListener/DcGeneral/Table/MetaModel/SelectModeButtonsListener.php
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
src/CoreBundle/EventListener/DcGeneral/Table/SelectModeButtonsListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters