@@ -93,6 +93,14 @@ class PagePermissions extends WireData implements Module {
93
93
*/
94
94
protected $hasOptionalPermissions = array();
95
95
96
+ /**
97
+ * Runtime caches
98
+ *
99
+ * @var array
100
+ *
101
+ */
102
+ protected $caches = array();
103
+
96
104
/**
97
105
* Establish permission hooks
98
106
*
@@ -1011,16 +1019,38 @@ class PagePermissions extends WireData implements Module {
1011
1019
$parent = $event->arguments(0);
1012
1020
if(!$parent instanceof Page || !$parent->id) $parent = null;
1013
1021
1014
- if($page->id == 1) {
1022
+ if($page->id == 1 || $page->isLocked() ) {
1015
1023
$moveable = false;
1016
1024
} else {
1017
1025
$moveable = $page->editable('parent');
1018
1026
}
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
+ }
1024
1054
}
1025
1055
1026
1056
$event->return = $moveable;
0 commit comments