Skip to content

Commit 8cd73f0

Browse files
committed
Implement size fields for PageImageType.
1 parent 0625bbe commit 8cd73f0

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

src/Type/Object/PageImageType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Youshido\GraphQL\Type\Scalar\IntType;
88
use Youshido\GraphQL\Type\ListType\ListType;
99
use ProcessWire\GraphQL\Type\InterfaceType\PageFileInterfaceType;
10+
use ProcessWire\GraphQL\Field\PageImage\PageImageSizeField;
1011

1112
class PageImageType extends AbstractObjectType {
1213

@@ -48,6 +49,8 @@ public function build($config)
4849
return $value->getVariations();
4950
}
5051
]);
52+
53+
$config->addField(new PageImageSizeField());
5154
}
5255

5356
public function getInterfaces()

0 commit comments

Comments
 (0)