Skip to content

Commit 7cfe227

Browse files
committed
Fix FieldtypePage bug when FieldtypePage:derefAsPageOrNullPage option is enabled.
1 parent 4987687 commit 7cfe227

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/Type/Inputfield/InputfieldPage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use GraphQL\Type\Definition\InputObjectType;
44
use GraphQL\Type\Definition\Type;
55
use ProcessWire\Page;
6+
use ProcessWire\FieldtypePage;
67
use ProcessWire\GraphQL\Cache;
78
use ProcessWire\GraphQL\Utils;
89

@@ -52,6 +53,7 @@ public static function inputField($field)
5253

5354
public static function setValue(Page $page, $field, $value)
5455
{
56+
$field->derefAsPage = FieldtypePage::derefAsPageArray;
5557
$fieldName = $field->name;
5658
$fieldValue = $page->$fieldName;
5759
if (isset($value['add'])) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Test\Field\Page\Fieldtype;
4+
5+
/**
6+
* Should properly handle FieldtypePage::derefAsPageArray option.
7+
*/
8+
use \ProcessWire\GraphQL\Test\GraphQLTestCase;
9+
use ProcessWire\FieldtypePage;
10+
use ProcessWire\GraphQL\Utils;
11+
12+
class FieldtypePageCaseFiveTest extends GraphQLTestCase {
13+
14+
const settings = [
15+
'login' => 'admin',
16+
'legalTemplates' => ['skyscraper', 'architect', 'city'],
17+
'legalFields' => ['architects', 'title'],
18+
'access' => [
19+
'fields' => [
20+
[
21+
'name' => 'architects',
22+
'derefAsPage' => FieldtypePage::derefAsPageOrNullPage,
23+
]
24+
]
25+
]
26+
];
27+
28+
public function testValue()
29+
{
30+
$architect = Utils::pages()->get(4476);
31+
$query = 'mutation createSkyscraper($page: SkyscraperCreateInput!){
32+
createSkyscraper (page: $page) {
33+
title,
34+
name,
35+
architects {
36+
list {
37+
id,
38+
}
39+
}
40+
}
41+
}';
42+
$name = 'new-sky-test-158';
43+
$title = 'New Sky Test 158';
44+
$variables = [
45+
'page' => [
46+
'name' => $name,
47+
'title' => $title,
48+
'parent' => "4114",
49+
'architects' => [
50+
'add' => [$architect->id]
51+
]
52+
]
53+
];
54+
$res = self::execute($query, $variables);
55+
$actual = $res->data->createSkyscraper;
56+
assertEquals($name, $actual->name, 'Sets the correct name.');
57+
assertEquals($title, $actual->title, 'Sets the correct title.');
58+
assertEquals($architect->id, $actual->architects->list[0]->id, 'Sets the correct architect.');
59+
}
60+
}

0 commit comments

Comments
 (0)