From 95a51a307083e8ce33cf417d6409afc10a7a8b2a Mon Sep 17 00:00:00 2001 From: i-just Date: Tue, 10 Jun 2025 09:43:14 +0100 Subject: [PATCH 1/3] only show copy all action menu item if the field is part of an element --- src/fields/Matrix.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/fields/Matrix.php b/src/fields/Matrix.php index 5dc356d7a2d..c54937b9db6 100644 --- a/src/fields/Matrix.php +++ b/src/fields/Matrix.php @@ -839,9 +839,22 @@ protected function actionMenuItems(): array if ($this->viewMode === self::VIEW_MODE_CARDS) { $view->registerJsWithVars(fn($copyAllId, $fieldId) => << { + const copyAllBtn = $('#' + $copyAllId); + $('#' + $copyAllId).on('activate', () => { Craft.cp.copyElements($('#' + $fieldId + ' > .nested-element-cards > .elements > li > .element')); }); + + setTimeout(() => { + const menu = copyAllBtn.closest('.menu').data('disclosureMenu'); + const trigger = menu.\$trigger; + const isElementFieldTrigger = trigger.parents('div.field').length; + + // only show the copy all button if the trigger is part of an element's field + menu.on('show', () => { + menu.toggleItem(copyAllBtn[0], isElementFieldTrigger); + }); + }, 1); })(); JS, [ $view->namespaceInputId($copyAllId), From 3b8581ccbf5dc635724b2bbf6b149032f173eb83 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 18 Jun 2025 12:11:48 -0700 Subject: [PATCH 2/3] Remove the copy button if the field ID doesn't exist Also make sure we're doing it for the inline-editable blocks view mode --- src/fields/Matrix.php | 87 ++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/src/fields/Matrix.php b/src/fields/Matrix.php index c54937b9db6..2b54c4b929e 100644 --- a/src/fields/Matrix.php +++ b/src/fields/Matrix.php @@ -837,56 +837,51 @@ protected function actionMenuItems(): array ]; if ($this->viewMode === self::VIEW_MODE_CARDS) { - $view->registerJsWithVars(fn($copyAllId, $fieldId) => << { - const copyAllBtn = $('#' + $copyAllId); - - $('#' + $copyAllId).on('activate', () => { - Craft.cp.copyElements($('#' + $fieldId + ' > .nested-element-cards > .elements > li > .element')); - }); - - setTimeout(() => { - const menu = copyAllBtn.closest('.menu').data('disclosureMenu'); - const trigger = menu.\$trigger; - const isElementFieldTrigger = trigger.parents('div.field').length; - - // only show the copy all button if the trigger is part of an element's field - menu.on('show', () => { - menu.toggleItem(copyAllBtn[0], isElementFieldTrigger); - }); - }, 1); -})(); -JS, [ - $view->namespaceInputId($copyAllId), - $view->namespaceInputId($this->getInputId()), - ]); + $copyAllJs = << { + Craft.cp.copyElements(field.find('> .nested-element-cards > .elements > li > .element')); +}); +JS; } else { - $view->registerJsWithVars(fn($copyAllId, $fieldId, $baseInfo) => << { - $('#' + $copyAllId).on('activate', () => { - const elementInfo = []; - $('#' + $fieldId + ' > .blocks > .matrixblock').each((i, element) => { - element = $(element); - elementInfo.push(Object.assign({ - id: element.data('id'), - draftId: element.data('draftId'), - revisionId: element.data('revisionId'), - ownerId: element.data('ownerId'), - siteId: element.data('siteId'), - }, $baseInfo)); - }); - Craft.cp.copyElements(elementInfo); + $baseInfo = Json::encode([ + 'type' => Entry::class, + 'fieldId' => $this->id, + ]); + $copyAllJs = << { + const elementInfo = []; + field.find('> .blocks > .matrixblock').each((i, element) => { + element = $(element); + elementInfo.push(Object.assign({ + id: element.data('id'), + draftId: element.data('draftId'), + revisionId: element.data('revisionId'), + ownerId: element.data('ownerId'), + siteId: element.data('siteId'), + }, $baseInfo)); }); + Craft.cp.copyElements(elementInfo); +}); +JS; + } + + $view->registerJsWithVars(fn($copyAllId, $fieldId) => << { + const copyAllBtn = $('#' + $copyAllId); + const field = $('#' + $fieldId); + if (field.length) { + $copyAllJs + } else { + setTimeout(() => { + const menu = copyAllBtn.closest('.menu').data('disclosureMenu'); + menu.removeItem(copyAllBtn[0]); + }, 1); + } })(); JS, [ - $view->namespaceInputId($copyAllId), - $view->namespaceInputId($this->getInputId()), - [ - 'type' => Entry::class, - 'fieldId' => $this->id, - ], - ]); - } + $view->namespaceInputId($copyAllId), + $view->namespaceInputId($this->getInputId()), + ]); } $parentItems = parent::actionMenuItems(); From 30faed49fd8105d1f3f9b7c47f7bd2a58950ba06 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 18 Jun 2025 12:12:32 -0700 Subject: [PATCH 3/3] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d53ca6b9766..78879cb3f13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Fixed an error that could occur when loading control panel resources on the front end. - Fixed a bug where entries’ section breadcrumbs were getting hyperlinked even if the section’s source was disabled. ([#17411](https://github.com/craftcms/cms/issues/17411)) - Fixed a bug where entries that were pasted within a Matrix field were losing custom field translations for other sites. ([17414](https://github.com/craftcms/cms/issues/17414)) +- Fixed a bug where Matrix fields’ chips were getting “Copy all entries” actions. ([#17404](https://github.com/craftcms/cms/issues/17404)) ## 5.7.10 - 2025-06-04