|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ProcessWire\GraphQL\Field\PageImage; |
| 4 | + |
| 5 | +use Youshido\GraphQL\Field\AbstractField; |
| 6 | +use Youshido\GraphQL\Config\Field\FieldConfig; |
| 7 | +use Youshido\GraphQL\Type\Scalar\IntType; |
| 8 | +use ProcessWire\GraphQL\Type\Object\PageImageType; |
| 9 | +use Youshido\GraphQL\Execution\ResolveInfo; |
| 10 | + |
| 11 | +class PageImageSizeField extends AbstractField{ |
| 12 | + |
| 13 | + public function getType() |
| 14 | + { |
| 15 | + return new PageImageType(); |
| 16 | + } |
| 17 | + |
| 18 | + public function getName() |
| 19 | + { |
| 20 | + return 'size'; |
| 21 | + } |
| 22 | + |
| 23 | + public function getDescription() |
| 24 | + { |
| 25 | + return 'Create a thumbnail of the PageImage with the desired size.'; |
| 26 | + } |
| 27 | + |
| 28 | + public function build(FieldConfig $config) |
| 29 | + { |
| 30 | + $config->addArgument('width', [ |
| 31 | + 'type' => new IntType(), |
| 32 | + 'description' => 'Target width of the new image', |
| 33 | + ]); |
| 34 | + $config->addArgument('height', [ |
| 35 | + 'type' => new IntType(), |
| 36 | + 'description' => 'Target height of the new image', |
| 37 | + ]); |
| 38 | + } |
| 39 | + |
| 40 | + public function resolve($value, array $args, ResolveInfo $info) |
| 41 | + { |
| 42 | + $width = isset($args['width']) ? $args['width'] : null; |
| 43 | + $height = isset($args['height']) ? $args['height'] : null; |
| 44 | + return $value->size($width, $height); |
| 45 | + } |
| 46 | +} |
0 commit comments