@@ -135,6 +135,14 @@ class DashboardPanelCollection extends DashboardPanel
135135 if ($markup === 'actions__') {
136136 $content = $this->renderPageActions($page);
137137 }
138+ // Special case: page status
139+ elseif ($markup === 'status__') {
140+ $content = $this->renderStatusIcon($page);
141+ }
142+ // Special case: published status toggle
143+ elseif (in_array($markup, ['published__', 'visible__'])) {
144+ $content = $this->renderStatusToggle($page, $markup);
145+ }
138146 // Special case: page icon
139147 elseif ($markup === 'page_icon') {
140148 $content = $this->renderIcon($page->getIcon());
@@ -232,6 +240,20 @@ class DashboardPanelCollection extends DashboardPanel
232240 $changed = true;
233241 }
234242 break;
243+ case 'show':
244+ $show = !!$value;
245+ $visible = !$page->isHidden();
246+ if ($page->editable() && $show && !$visible) {
247+ $page->removeStatus(Page::statusHidden);
248+ $page->save('status');
249+ $changed = true;
250+ }
251+ if (!$show && $visible) {
252+ $page->addStatus(Page::statusHidden);
253+ $page->save('status');
254+ $changed = true;
255+ }
256+ break;
235257 case 'trash':
236258 $trash = !!$value;
237259 $trashed = $page->isTrash();
@@ -284,6 +306,7 @@ class DashboardPanelCollection extends DashboardPanel
284306 $this->listPage = $this->getPageFromObjectOrSelectorOrID($this->data['list'] ?? null);
285307 $this->editMode = $this->data['editMode'] ?? self::windowModeBlank;
286308 $this->viewMode = $this->data['viewMode'] ?? self::windowModeBlank;
309+ $this->addUrlParams = $this->data['addUrlParams'] ?? [];
287310
288311 if (is_string($this->collection)) {
289312 $this->collection = $this->pages->find($this->collection);
@@ -404,6 +427,7 @@ class DashboardPanelCollection extends DashboardPanel
404427 'modalAutoclose' => self::modalAutocloseAdd,
405428 'reloadOnModalClose' => true,
406429 ];
430+ $action = $this->setQueryParameter($action, $this->addUrlParams);
407431 if (self::windowModeModal === $mode) {
408432 $action = $this->setQueryParameter($action, 'modal', 1);
409433 }
@@ -554,4 +578,61 @@ class DashboardPanelCollection extends DashboardPanel
554578
555579 return implode(' ', $thumbnails);
556580 }
581+
582+ /**
583+ * Render status icon.
584+ */
585+ protected function renderStatusIcon(Page $page)
586+ {
587+ if ($page->hasStatus(Page::statusTrash)) {
588+ $icon = 'trash-can';
589+ $tooltip = $this->_('In Trash');
590+ } elseif ($page->hasStatus(Page::statusUnpublished)) {
591+ $icon = 'pen';
592+ $tooltip = $this->_('Draft');
593+ } elseif ($page->hasStatus(Page::statusHidden)) {
594+ $icon = 'eye-slash';
595+ $tooltip = $this->_('Hidden');
596+ } else {
597+ $icon = 'circle-check';
598+ $tooltip = $this->_('Published');
599+ }
600+ $icon = $this->renderIcon($icon);
601+ return "<span class='tooltip' title='{$tooltip}'>{$icon}</span>";
602+ }
603+
604+ /**
605+ * Render publish/visibility toggle.
606+ */
607+ protected function renderStatusToggle(Page $page, $status = 'published')
608+ {
609+ $status = $this->wire()->sanitizer->option($status, ['published', 'visible']) ?? 'published';
610+
611+ switch ($status) {
612+ case 'visible':
613+ $action = 'show';
614+ $statusFlag = Page::statusHidden;
615+ $labelInactive = $this->_('Hidden');
616+ $labelActive = $this->_('Visible');
617+ break;
618+ case 'published':
619+ default:
620+ $action = 'publish';
621+ $statusFlag = Page::statusUnpublished;
622+ $labelInactive = $this->_('Draft');
623+ $labelActive = $this->_('Published');
624+ break;
625+ }
626+
627+ $active = !$page->hasStatus($statusFlag);
628+ $checked = $active ? 'checked' : '';
629+ $tooltip = $active ? $labelActive : $labelInactive;
630+
631+ return "
632+ <label class='uk-switch tooltip' for='page-{$status}-{$page}' title='{$tooltip}'>
633+ <input type='checkbox' id='page-{$status}-{$page}' name='actions[{$action}][{$page}]' value='1' {$checked}>
634+ <div class='uk-switch-slider'></div>
635+ </label>
636+ ";
637+ }
557638}
0 commit comments