1919
2020use ProcessWire \GraphQL \Type \Object \TemplatedPageType ;
2121use ProcessWire \GraphQL \Type \Input \TemplatedPage \UpdateInputType ;
22+ use ProcessWire \GraphQL \Utils ;
2223
2324class UpdateTemplatedPage extends AbstractField {
2425
@@ -98,6 +99,8 @@ public function resolve($value, array $args, ResolveInfo $info)
9899 // make sure the page is allowed as a child for parent
99100 $ childTemplates = $ parent ->template ->childTemplates ;
100101 if (count ($ childTemplates ) && !in_array ($ this ->template ->id , $ childTemplates )) throw new ValidationException ("not allowed to be a child for `parent`. " );
102+
103+ $ p ->parent = $ parent ;
101104 }
102105
103106 if (isset ($ values ['name ' ])) {
@@ -107,10 +110,17 @@ public function resolve($value, array $args, ResolveInfo $info)
107110 if (!$ name ) throw new ValidationException ('value for `name` field is invalid, ' );
108111
109112 // find out if the name is taken
113+ if (!isset ($ values ['parent ' ])) $ parent = $ p ->parent ;
110114 $ taken = $ pages ->find ("parent= $ parent, name= $ name " )->count ();
111115 if ($ taken ) throw new ValidationException ('`name` is already taken. ' );
116+
117+ $ p ->name = $ name ;
112118 }
113119
120+ // unset the parent and name as we set them above
121+ unset($ values ['parent ' ]);
122+ unset($ values ['name ' ]);
123+
114124 // update the values from client
115125 foreach ($ values as $ fieldName => $ value ) {
116126 $ field = $ fields ->get ($ fieldName );
0 commit comments