Skip to content

Commit d30ec3d

Browse files
committed
Add support for FieldtypeMapMarker.
1 parent ffb15b0 commit d30ec3d

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

src/Field/Mutation/CreateTemplatedPage.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ public function resolve($value, array $args, ResolveInfo $info)
115115
foreach ($values as $fieldName => $value) {
116116
$field = $fields->get($fieldName);
117117
if (!$field instanceof Field) continue;
118+
if ($field->type->className() === 'FieldtypeMapMarker') {
119+
$p->$fieldName->lat = $value['lat'];
120+
$p->$fieldName->lng = $value['lng'];
121+
$p->$fieldName->address = $value['address'];
122+
$p->$fieldName->zoom = $value['zoom'];
123+
continue;
124+
}
118125
if ($field->type->className() === 'FieldtypePage') $value = implode('|', $value);
119126
$p->$fieldName = $value;
120127
}

src/Field/Mutation/UpdateTemplatedPage.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ public function resolve($value, array $args, ResolveInfo $info)
125125
foreach ($values as $fieldName => $value) {
126126
$field = $fields->get($fieldName);
127127
if (!$field instanceof Field) continue;
128+
if ($field->type->className() === 'FieldtypeMapMarker') {
129+
$p->$fieldName->lat = $value['lat'];
130+
$p->$fieldName->lng = $value['lng'];
131+
$p->$fieldName->address = $value['address'];
132+
$p->$fieldName->zoom = $value['zoom'];
133+
continue;
134+
}
128135
if ($field->type->className() === 'FieldtypePage') $value = implode('|', $value);
129136
$p->$fieldName = $value;
130137
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Field\Page\Fieldtype;
4+
5+
use ProcessWire\GraphQL\Field\Page\Fieldtype\AbstractFieldtype;
6+
use ProcessWire\GraphQL\Type\Object\MapMarkerType;
7+
use ProcessWire\GraphQL\Type\Input\Inputfield\InputfieldMapMarker;
8+
9+
class FieldtypeMapMarker extends AbstractFieldtype {
10+
11+
public function getDefaultType()
12+
{
13+
return new MapMarkerType();
14+
}
15+
16+
public function getInputfieldType($type = null)
17+
{
18+
return new InputfieldMapMarker();
19+
}
20+
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Type\Input\Inputfield;
4+
5+
use Youshido\GraphQL\Type\InputObject\AbstractInputObjectType;
6+
use Youshido\GraphQL\Type\Scalar\IntType;
7+
use Youshido\GraphQL\Type\Scalar\FloatType;
8+
use Youshido\GraphQL\Type\Scalar\StringType;
9+
10+
class InputFieldMapMarker extends AbstractInputObjectType {
11+
12+
public function build($config)
13+
{
14+
$config->addField('lat', new FloatType());
15+
$config->addField('lng', new FloatType());
16+
$config->addField('address', new stringType());
17+
$config->addField('zoom', new IntType());
18+
}
19+
20+
}

src/Type/Object/MapMarkerType.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Type\Object;
4+
5+
use Youshido\GraphQL\Type\Object\AbstractObjectType;
6+
use Youshido\GraphQL\Type\Scalar\FloatType;
7+
use Youshido\GraphQL\Type\Scalar\IntType;
8+
use Youshido\GraphQL\Type\Scalar\StringType;
9+
10+
class MapMarkerType extends AbstractObjectType {
11+
12+
public function getName()
13+
{
14+
return 'MapMarker';
15+
}
16+
17+
public function getDescription()
18+
{
19+
return 'Represents the `FieldtypeMapMarker` value.';
20+
}
21+
22+
public function build($config)
23+
{
24+
$config->addField('lat',[
25+
'type' => new FloatType(),
26+
'description' => 'The latitude of the MapMarker.',
27+
'resolve' => function ($value) {
28+
return (float) $value->lat;
29+
}
30+
]);
31+
32+
$config->addField('lng',[
33+
'type' => new FloatType(),
34+
'description' => 'The longitude of the MapMarker.',
35+
'resolve' => function ($value) {
36+
return (float) $value->lng;
37+
}
38+
]);
39+
40+
$config->addField('address',[
41+
'type' => new StringType(),
42+
'description' => 'The address of the MapMarker.',
43+
'resolve' => function ($value) {
44+
return (string) $value->adress;
45+
}
46+
]);
47+
48+
$config->addField('zoom',[
49+
'type' => new IntType(),
50+
'description' => 'The zoom of the MapMarker.',
51+
'resolve' => function ($value) {
52+
return (integer) $value->zoom;
53+
}
54+
]);
55+
}
56+
57+
}

0 commit comments

Comments
 (0)