Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Help with integration of third party field #138

Open
jan-thoma opened this issue Aug 21, 2018 · 1 comment
Open

Help with integration of third party field #138

jan-thoma opened this issue Aug 21, 2018 · 1 comment

Comments

@jan-thoma
Copy link

jan-thoma commented Aug 21, 2018

Im trying to get this plugin to work with CraftQL. To not have to mess with the plugins code i want to do this in a custom module:

<?php

namespace craftQlPluginHelper;

use Craft;
use yii\base\Event;

class Module extends \yii\base\Module
{
    public function init()
    {
        parent::init();

        Event::on(\TDE\GeoAddress\fields\GeoAddressField::class, 'craftQlGetFieldSchema', function (\markhuot\CraftQL\Events\GetFieldSchema $event)
        {
            $field = $event->sender;

            Craft::info($field, __METHOD__);
        });
    }
}

The event fires sucessfully:

2018-08-21 15:32:48 [213.180.172.94][-][-][info][craftQlPluginHelper\{closure}] unserialize('O:37:"TDE\\GeoAddress\\fields\\GeoAddressField":23:{s:26:"' . "\0" . 'craft\\base\\Field' . "\0" . '_isFresh";N;s:23:"' . "\0" . 'yii\\base\\Model' . "\0" . '_errors";N;s:27:"' . "\0" . 'yii\\base\\Model' . "\0" . '_validators";N;s:25:"' . "\0" . 'yii\\base\\Model' . "\0" . '_scenario";s:7:"default";s:27:"' . "\0" . 'yii\\base\\Component' . "\0" . '_events";a:0:{}s:35:"' . "\0" . 'yii\\base\\Component' . "\0" . '_eventWildcards";a:0:{}s:30:"' . "\0" . 'yii\\base\\Component' . "\0" . '_behaviors";a:0:{}s:2:"id";i:204;s:11:"dateCreated";O:8:"DateTime":3:{s:4:"date";s:26:"2018-08-21 11:21:44.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/Zurich";}s:11:"dateUpdated";O:8:"DateTime":3:{s:4:"date";s:26:"2018-08-21 14:55:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/Zurich";}s:7:"groupId";i:24;s:4:"name";s:11:"Company geo";s:6:"handle";s:10:"companyGeo";s:7:"context";s:6:"global";s:12:"instructions";s:0:"";s:17:"translationMethod";s:4:"none";s:20:"translationKeyFormat";N;s:9:"oldHandle";N;s:12:"columnPrefix";N;s:8:"layoutId";N;s:5:"tabId";N;s:8:"required";N;s:9:"sortOrder";N;}')

From there i'm lost. Would be great if someone could point me in the right direction.

ed. fixed broken link.

markhuot added a commit that referenced this issue Sep 7, 2018
@markhuot
Copy link
Owner

markhuot commented Sep 7, 2018

@jan-thoma, the next step would be to start adding the fields that GeoAddress supports. E.g.,

$field = $event->sender;
$schema = $event->schema;

$object = $schema->createObjectType('GeoAddress');
$object->addStringField('street');
$object->addStringField('zip');
$object->addStringField('city');
$object->addStringField('country');
$object->addStringField('lat');
$object->addStringField('lng');

$schema->addStringField($field)
    ->type($object)
    ->resolve(function ($root, $args) use ($field) {
        return $root->{$field->handle};
    });

This is implemented as an example on the geo-address-field-schema branch over here, https://github.com/markhuot/craftql/blob/geo-address-field-schema/src/Listeners/GetGeoAddressFieldSchema.php

Let me know if you'd like to merge this or keep support for it in your own plugin. Note: I could never get this field to work for me, it never triggered Google Geocoding requests.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants