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 diff --git a/src/fields/Matrix.php b/src/fields/Matrix.php index 5dc356d7a2d..2b54c4b929e 100644 --- a/src/fields/Matrix.php +++ b/src/fields/Matrix.php @@ -837,43 +837,51 @@ protected function actionMenuItems(): array ]; if ($this->viewMode === self::VIEW_MODE_CARDS) { - $view->registerJsWithVars(fn($copyAllId, $fieldId) => << { - $('#' + $copyAllId).on('activate', () => { - Craft.cp.copyElements($('#' + $fieldId + ' > .nested-element-cards > .elements > li > .element')); - }); -})(); -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();