From 9dc7ea933e8f70a9699a90c5ad8fc35d400582fb Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Fri, 12 Jan 2018 08:29:40 -0500 Subject: [PATCH 1/3] updating support for craftql --- src/SimpleMap.php | 9 +++++ src/fields/MapField.php | 59 ------------------------------ src/listeners/GetCraftQLSchema.php | 35 ++++++++++++++++++ 3 files changed, 44 insertions(+), 59 deletions(-) create mode 100644 src/listeners/GetCraftQLSchema.php diff --git a/src/SimpleMap.php b/src/SimpleMap.php index 0d23b5c..d42beb5 100644 --- a/src/SimpleMap.php +++ b/src/SimpleMap.php @@ -76,6 +76,15 @@ public function init () CraftVariable::EVENT_INIT, [$this, 'onRegisterVariable'] ); + + // CraftQL Support + if (class_exists(\markhuot\CraftQL\CraftQL::class)) { + Event::on( + MapField::class, + 'craftQlGetFieldSchema', + [new \ether\simplemap\listeners\GetCraftQLSchema, 'handle'] + ); + } } // Craft: Settings diff --git a/src/fields/MapField.php b/src/fields/MapField.php index 8e78af8..67ee1f5 100644 --- a/src/fields/MapField.php +++ b/src/fields/MapField.php @@ -535,63 +535,4 @@ public function afterElementSave (ElementInterface $element, bool $isNew) parent::afterElementSave($element, $isNew); } - // 3rd Party Support - // ========================================================================= - - // CraftQL - // ------------------------------------------------------------------------- - - /** @var ObjectType|null */ - private static $_simpleMapGraphQLObject; - - /** - * I dunno, but it works. - * - * @return ObjectType - */ - private static function object() { - if (self::$_simpleMapGraphQLObject) - return self::$_simpleMapGraphQLObject; - - $parts = []; - - foreach (MapService::$parts as $part) { - $parts[$part] = Type::string(); - $parts[$part . '_short'] = Type::string(); - } - - return self::$_simpleMapGraphQLObject = new ObjectType([ - 'name' => 'SimpleMap', - 'fields' => [ - 'lat' => Type::string(), - 'lng' => Type::string(), - 'zoom' => Type::string(), - 'address' => Type::string(), - 'parts' => [ - 'type' => new ObjectType([ - 'name' => 'SimpleMapParts', - 'fields' => $parts, - ]) - ], - ], - ]); - } - - /** - * Support for CraftQL - * - * @see https://github.com/markhuot/craftql - */ - public function getGraphQLQueryFields () - { - $field = $this->owner; - - return [ - $field->handle => [ - 'type' => self::object(), - 'description' => $field->instructions, - ] - ]; - } - } \ No newline at end of file diff --git a/src/listeners/GetCraftQLSchema.php b/src/listeners/GetCraftQLSchema.php new file mode 100644 index 0000000..743c0b7 --- /dev/null +++ b/src/listeners/GetCraftQLSchema.php @@ -0,0 +1,35 @@ +handled = true; + + $partsObject = $event->schema->createObjectType('SimpleMapDataParts'); + foreach (MapService::$parts as $part) { + $partsObject->addStringField($part); + $partsObject->addStringField($part . '_short'); + } + + $fieldObject = $event->schema->createObjectType('SimpleMapData'); + $fieldObject->addStringField('lat'); + $fieldObject->addStringField('lng'); + $fieldObject->addStringField('zoom'); + $fieldObject->addStringField('address'); + $fieldObject->addField('parts')->type($partsObject); + + $event->schema->addField($event->sender) + ->type($fieldObject); + } +} From e8c3e991f1134c81f00088255f6b531468c0367e Mon Sep 17 00:00:00 2001 From: Tam Date: Fri, 19 Jan 2018 23:44:11 +0000 Subject: [PATCH 2/3] Fixes #71, Fixes #73, Fixes #74, Breaks pagination. --- CHANGELOG.md | 9 ++++++ README.md | 4 +-- composer.json | 5 ++-- src/SimpleMap.php | 7 +++-- src/listeners/GetCraftQLSchema.php | 46 ++++++++++++++++-------------- src/resources/SimpleMap_Map.css | 32 +++++++++++++++++---- src/services/MapService.php | 26 +++++++++++++---- src/templates/field-input.twig | 2 +- 8 files changed, 90 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52373ae..2882f14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 3.2.0 - WIP +### Fixed +- Not #70 yet + +### Improved +- Updated CraftQL support (via @markhuot) +- Updated Mapbox example to use latest API +- Improved address and lat/lng input sizing on smaller screens and in a HUD + ## 3.1.3 - 2017-12-18 ### Fixed - Map fields no longer cause global sets to fail to save! diff --git a/README.md b/README.md index b38f6c4..0934ecf 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ Using [Google Maps](https://developers.google.com/maps/documentation/javascript/ And [Mapbox](https://www.mapbox.com/mapbox-gl-js/api/): ```twig - - + +