Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/Listeners/GetIconPickerFieldSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace markhuot\CraftQL\Listeners;

/**
* Schema for Dolphiq/craft3-iconpicker
*/

class GetIconPickerFieldSchema
{

/**
* Handle the request for the schema
*
* @param \markhuot\CraftQL\Events\GetFieldSchema $event
* @return void
*/
function handle($event) {
$event->handled = true;

$field = $event->sender;

$event->schema->addField($field)
->arguments(function ($field) {
$field->addEnumArgument('as')
->values([
'hex',
'char',
'charHex',
'span',
'class'
]);
})
->description('Use argument [as] to change the output of the icon')
->resolve(function ($root, $args) use ($field) {
if (!empty($args['as'])) {
return (string)$root->{$field->handle}->{'getIcon' . ucfirst($args['as'])}();
}

return (string)$root->{$field->handle}->getChar();
});

$event->query->addStringArgument($event->sender);
$event->mutation->addStringArgument($event->sender);
}
}
5 changes: 5 additions & 0 deletions src/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
new \markhuot\CraftQL\Listeners\GetSuperTableFieldSchema,
],
],
\plugins\dolphiq\iconpicker\fields\Iconpicker::class => [
'craftQlGetFieldSchema' => [
new \markhuot\CraftQL\Listeners\GetIconPickerFieldSchema,
],
],
\craft\fields\Table::class => [
'craftQlGetFieldSchema' => [
new \markhuot\CraftQL\Listeners\GetTableFieldSchema,
Expand Down