Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9737b4e

Browse filesBrowse files
Update Page::moveable method to also consider its template.parentTemplates setting so that it can return false when no potential parents exist using allowed templates. Also should fix processwire/processwire-issues#1901
1 parent 37416f8 commit 9737b4e
Copy full SHA for 9737b4e

File tree

Expand file treeCollapse file tree

1 file changed

+36
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+36
-6
lines changed

‎wire/modules/PagePermissions.module

Copy file name to clipboardExpand all lines: wire/modules/PagePermissions.module
+36-6Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ class PagePermissions extends WireData implements Module {
9393
*/
9494
protected $hasOptionalPermissions = array();
9595

96+
/**
97+
* Runtime caches
98+
*
99+
* @var array
100+
*
101+
*/
102+
protected $caches = array();
103+
96104
/**
97105
* Establish permission hooks
98106
*
@@ -1011,16 +1019,38 @@ class PagePermissions extends WireData implements Module {
10111019
$parent = $event->arguments(0);
10121020
if(!$parent instanceof Page || !$parent->id) $parent = null;
10131021

1014-
if($page->id == 1) {
1022+
if($page->id == 1 || $page->isLocked()) {
10151023
$moveable = false;
10161024
} else {
10171025
$moveable = $page->editable('parent');
10181026
}
1019-
1020-
if($moveable && $parent) {
1021-
$moveable = $parent->addable($page);
1022-
} else if($parent && $parent->isTrash() && $parent->id == $this->wire()->config->trashPageID) {
1023-
$moveable = $page->deletable();
1027+
1028+
if($parent) {
1029+
// parent specified
1030+
if($moveable) {
1031+
$moveable = $parent->addable($page);
1032+
} else if($parent->isTrash() && $parent->id == $this->wire()->config->trashPageID) {
1033+
$moveable = $page->deletable();
1034+
}
1035+
} else if($moveable) {
1036+
// moveable but no parent specified
1037+
// check to see if there is more than one parent it can move to
1038+
$parentTemplates = $page->template->parentTemplates;
1039+
if(empty($parentTemplates)) {
1040+
// any parent that accepts any children is allowed
1041+
} else {
1042+
// only specific parents are allowed
1043+
$templatesStr = implode('|', $parentTemplates);
1044+
$cacheKey = "moveable.$templatesStr";
1045+
if(isset($this->caches[$cacheKey])) {
1046+
$moveable = $this->caches[$cacheKey];
1047+
} else {
1048+
$pages = $this->wire()->pages;
1049+
$s = "include=unpublished, id!=$page->parent_id, templates_id=$templatesStr";
1050+
$moveable = $pages->count($s) > 0;
1051+
$this->caches[$cacheKey] = $moveable;
1052+
}
1053+
}
10241054
}
10251055

10261056
$event->return = $moveable;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.