Skip to content

Commit fed5304

Browse files
committed
Refactor
1 parent ed38f59 commit fed5304

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

Dashboard.module

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Dashboard extends Process implements Module
116116
'headline_without_user' => $this->_('Welcome'),
117117
'panel_not_found' => $this->_('Dashboard panel not found: %s'),
118118
'empty_panel_notice' => $this->_('Your dashboard is empty'),
119-
'setup_hint' => $this->sanitizer->entitiesMarkdown(
119+
'setup_hint' => $this->wire()->sanitizer->entitiesMarkdown(
120120
$this->_('Learn how to add and configure panels reading the [documentation](%s).')
121121
),
122122
'get_started' => $this->_('Get started'),
@@ -174,19 +174,17 @@ class Dashboard extends Process implements Module
174174
protected function addUserNavItem()
175175
{
176176
$this->addHookAfter('AdminThemeFramework::getUserNavArray', function ($event) {
177-
$navArray = $event->return;
178-
179177
$page = $this->getDashboardPageInNav() ?: $this->getDashboardPage();
180178
if ($page && $page->viewable) {
181179
$icon = $this->modules->getModuleInfoProperty($this, 'icon');
182-
array_unshift($navArray, [
180+
$nav = $event->return;
181+
array_unshift($nav, [
183182
'url' => $page->url,
184183
'title' => $this->texts->usernav,
185184
'icon' => $icon,
186185
]);
186+
$event->return = $nav;
187187
}
188-
189-
$event->return = $navArray;
190188
});
191189
}
192190

@@ -195,7 +193,7 @@ class Dashboard extends Process implements Module
195193
*/
196194
protected function getDashboardPage()
197195
{
198-
$admin = $this->pages->get(2);
196+
$admin = $this->wire()->pages->get($this->wire()->config->adminRootPageID);
199197
$children = $admin->children('include=hidden, check_access=0');
200198

201199
return $admin->and($children)->get("process={$this}");
@@ -206,7 +204,7 @@ class Dashboard extends Process implements Module
206204
*/
207205
protected function getDashboardPageInNav()
208206
{
209-
$admin = $this->pages->get(2);
207+
$admin = $this->wire()->pages->get($this->wire()->config->adminRootPageID);
210208
$pages = $admin->children('check_access=0');
211209

212210
return $pages->get("process={$this}");
@@ -218,7 +216,7 @@ class Dashboard extends Process implements Module
218216
public function ___execute()
219217
{
220218
// Redirect admin homepage to process page if in navigation
221-
if ($this->page->id === 2) {
219+
if ($this->page->id === $this->wire()->config->adminRootPageID) {
222220
$page = $this->getDashboardPageInNav();
223221
if ($page) {
224222
$this->session->redirect($page->url);
@@ -399,7 +397,7 @@ class Dashboard extends Process implements Module
399397
*/
400398
private function getPanelClassName($name)
401399
{
402-
$panelName = $this->sanitizer()->pascalCase($name);
400+
$panelName = $this->wire()->sanitizer->pascalCase($name);
403401

404402
return self::panelModulePrefix.$panelName;
405403
}
@@ -409,10 +407,10 @@ class Dashboard extends Process implements Module
409407
*/
410408
public function sanitizePanelSize($input)
411409
{
412-
$size = $this->sanitizer->option($input, self::panelSizes);
410+
$size = $this->wire()->sanitizer->option($input, self::panelSizes);
413411
if (!$size) {
414412
$default = $this->settings->defaultPanelSize;
415-
$size = $this->sanitizer->option($default, self::panelSizes);
413+
$size = $this->wire()->sanitizer->option($default, self::panelSizes);
416414
}
417415

418416
return $size ?: self::fallbackPanelSize;
@@ -554,7 +552,7 @@ class Dashboard extends Process implements Module
554552
parent::___install();
555553
if ($this->installOnHomepage) {
556554
// Set the admin process to use this module
557-
$admin = $this->pages->get(2);
555+
$admin = $this->wire()->pages->get($this->wire()->config->adminRootPageID);
558556
$admin->process = $this;
559557
$admin->save();
560558
}
@@ -572,7 +570,7 @@ class Dashboard extends Process implements Module
572570
parent::___uninstall();
573571
if ($this->installOnHomepage) {
574572
// Restore the admin process to use ProcessHome again
575-
$admin = $this->pages->get(2);
573+
$admin = $this->wire()->pages->get($this->wire()->config->adminRootPageID);
576574
$admin->process = 'ProcessHome';
577575
$admin->save();
578576
}

DashboardPanel.class.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,20 @@ protected function renderAttributes($attributes = [])
429429
*
430430
* @return string Updated URL
431431
*/
432-
protected function setQueryParameter($url, $key, $value)
432+
protected function setQueryParameter($url, $key, $value = null)
433433
{
434434
$info = parse_url($url);
435435
$query = $info['query'] ?? '';
436436
parse_str($query, $params);
437437

438-
$params[$key] = $value;
438+
if (is_array($key)) {
439+
foreach ($key as $k => $v) {
440+
$params[$k] = $v;
441+
}
442+
} else {
443+
$params[$key] = $value;
444+
}
445+
439446
$query = http_build_query($params);
440447

441448
$result = $info['path'] ?? '';
@@ -543,12 +550,12 @@ final protected function view($view, $variables)
543550
*
544551
* @param Page|int|string|null $input
545552
*
546-
* @return Page|null
553+
* @return Page|NullPage|null
547554
*/
548555
protected function getPageFromObjectOrSelectorOrID($input)
549556
{
550557
if (!$input) {
551-
return;
558+
return null;
552559
}
553560

554561
if (is_object($input) && $input instanceof Page) {
@@ -559,6 +566,6 @@ protected function getPageFromObjectOrSelectorOrID($input)
559566
$page = $this->pages->get($input);
560567
}
561568

562-
return $page;
569+
return $page ?? null;
563570
}
564571
}

0 commit comments

Comments
 (0)