Skip to content

Commit 97efefb

Browse files
authored
Merge pull request #16623 from craftcms/bugfix/16556-edit-element-duplicated-view-links
Filter out "View in a new tab” action menu item, so that we don't show it twice
2 parents d03af79 + d44c7d0 commit 97efefb

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

CHANGELOG-WIP.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Release Notes for Craft CMS 5.7 (WIP)
22

33
### Content Management
4+
- Element edit pages no longer have a “View in a new tab” action, if they also have a “View” button. ([#16623](https://github.com/craftcms/cms/pull/16623))
45
- Removed the “Always show focus rings” user accessibility preference. ([#16585](https://github.com/craftcms/cms/pull/16585))
56

67
### Accessibility

src/controllers/ElementsController.php

+47-8
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,7 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
402402
$isUnpublishedDraft,
403403
$isDraft
404404
))
405-
->actionMenuItems(fn() => $element->id ? array_filter(
406-
$element->getActionMenuItems(),
407-
fn(array $item) => !str_starts_with($item['id'] ?? '', 'action-edit-'),
408-
) : [])
405+
->actionMenuItems(fn() => $this->_actionMenuItems($element, $previewTargets))
409406
->noticeHtml($notice)
410407
->errorSummary(fn() => $this->_errorSummary($element))
411408
->prepareScreen(
@@ -1069,8 +1066,7 @@ private function _prepareEditor(
10691066

10701067
$settings = $jsSettingsFn($form);
10711068

1072-
$isSlideout = Craft::$app->getRequest()->getHeaders()->has('X-Craft-Container-Id');
1073-
if ($isSlideout) {
1069+
if ($this->_isSlideout()) {
10741070
$this->view->registerJsWithVars(fn($settings) => <<<JS
10751071
$('#$containerId').data('elementEditorSettings', $settings);
10761072
JS, [
@@ -1084,8 +1080,6 @@ private function _prepareEditor(
10841080
]);
10851081
}
10861082

1087-
1088-
10891083
// Give the element a chance to do things here too
10901084
$element->prepareEditScreen($response, $containerId);
10911085
}
@@ -1248,6 +1242,51 @@ private function _editorSidebar(
12481242
return trim(implode("\n", $components));
12491243
}
12501244

1245+
/**
1246+
* Returns an array of action menu items for the element.
1247+
*
1248+
* @param ElementInterface $element
1249+
* @param array $previewTargets
1250+
* @return array
1251+
*/
1252+
private function _actionMenuItems(ElementInterface $element, array $previewTargets): array
1253+
{
1254+
if (!$element->id) {
1255+
return [];
1256+
}
1257+
1258+
$hideViewAction = !empty($previewTargets) && !$this->_isSlideout();
1259+
1260+
return array_filter(
1261+
$element->getActionMenuItems(),
1262+
function(array $item) use ($hideViewAction) {
1263+
// filter out "Edit" item - no point showing edit action on the edit page,
1264+
if (str_starts_with($item['id'] ?? '', 'action-edit-')) {
1265+
return false;
1266+
}
1267+
1268+
// and "View in a new tab" item, if we have at least one preview target, and it's not a slideout
1269+
// as that action is already covered by the "View" button;
1270+
// (https://github.com/craftcms/cms/issues/16556)
1271+
if ($hideViewAction && str_starts_with($item['id'] ?? '', 'action-view-')) {
1272+
return false;
1273+
}
1274+
1275+
return true;
1276+
},
1277+
);
1278+
}
1279+
1280+
/**
1281+
* Returns whether this is for a slideout.
1282+
*
1283+
* @return bool
1284+
*/
1285+
private function _isSlideout(): bool
1286+
{
1287+
return $this->request->getHeaders()->has('X-Craft-Container-Id');
1288+
}
1289+
12511290
private function _draftNotice(): string
12521291
{
12531292
return

0 commit comments

Comments
 (0)