File tree Expand file tree Collapse file tree
modules/graphql_core/src/Plugin/GraphQL/Fields Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?php
22
3- namespace Drupal \graphql_core \Plugin \GraphQL \Fields \Images ;
3+ namespace Drupal \graphql_core \Plugin \GraphQL \Fields \Entity \ Fields \ Image ;
44
5- use Drupal \Core \Cache \Cache ;
65use Drupal \Core \DependencyInjection \DependencySerializationTrait ;
76use Drupal \Core \Image \ImageFactory ;
87use Drupal \Core \Plugin \ContainerFactoryPluginInterface ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Drupal \graphql_core \Plugin \GraphQL \Fields \Entity \Fields \Image ;
4+
5+ use Drupal \graphql \Plugin \GraphQL \Fields \FieldPluginBase ;
6+ use Drupal \image \Plugin \Field \FieldType \ImageItem ;
7+ use Youshido \GraphQL \Execution \ResolveInfo ;
8+
9+ /**
10+ * Retrieve the image height.
11+ *
12+ * @GraphQLField(
13+ * id = "image_height",
14+ * secure = true,
15+ * name = "height",
16+ * type = "Int",
17+ * provider = "image",
18+ * field_types = {"image"},
19+ * deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
20+ * )
21+ */
22+ class ImageHeight extends FieldPluginBase {
23+
24+ /**
25+ * {@inheritdoc}
26+ */
27+ protected function resolveValues ($ value , array $ args , ResolveInfo $ info ) {
28+ if ($ value instanceof ImageItem && $ value ->entity ->access ('view ' )) {
29+ yield (int ) $ value ->height ;
30+ }
31+ }
32+
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Drupal \graphql_core \Plugin \GraphQL \Fields \Entity \Fields \Image ;
4+
5+ use Drupal \graphql \Plugin \GraphQL \Fields \FieldPluginBase ;
6+ use Drupal \image \Plugin \Field \FieldType \ImageItem ;
7+ use Youshido \GraphQL \Execution \ResolveInfo ;
8+
9+ /**
10+ * Retrieve the image url.
11+ *
12+ * @GraphQLField(
13+ * id = "image_url",
14+ * secure = true,
15+ * name = "url",
16+ * type = "String",
17+ * field_types = {"image"},
18+ * provider = "image",
19+ * deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
20+ * )
21+ */
22+ class ImageUrl extends FieldPluginBase {
23+
24+ /**
25+ * {@inheritdoc}
26+ */
27+ protected function resolveValues ($ value , array $ args , ResolveInfo $ info ) {
28+ if ($ value instanceof ImageItem && $ value ->entity ->access ('view ' )) {
29+ yield file_create_url ($ value ->entity ->getFileUri ());
30+ }
31+ }
32+
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Drupal \graphql_core \Plugin \GraphQL \Fields \Entity \Fields \Image ;
4+
5+ use Drupal \graphql \Plugin \GraphQL \Fields \FieldPluginBase ;
6+ use Drupal \image \Plugin \Field \FieldType \ImageItem ;
7+ use Youshido \GraphQL \Execution \ResolveInfo ;
8+
9+ /**
10+ * Retrieve the image width.
11+ *
12+ * @GraphQLField(
13+ * id = "image_width",
14+ * secure = true,
15+ * name = "width",
16+ * type = "Int",
17+ * provider = "image",
18+ * field_types = {"image"},
19+ * deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
20+ * )
21+ */
22+ class ImageWidth extends FieldPluginBase {
23+
24+ /**
25+ * {@inheritdoc}
26+ */
27+ protected function resolveValues ($ value , array $ args , ResolveInfo $ info ) {
28+ if ($ value instanceof ImageItem && $ value ->entity ->access ('view ' )) {
29+ yield (int ) $ value ->width ;
30+ }
31+ }
32+
33+ }
Original file line number Diff line number Diff line change 1414 * secure = true,
1515 * name = "height",
1616 * type = "Int",
17- * provider = "image",
1817 * parents = {"ImageResource"},
19- * field_types = {"image"},
20- * deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
18+ * provider = "image"
2119 * )
2220 */
2321class ImageResourceHeight extends FieldPluginBase {
@@ -26,13 +24,7 @@ class ImageResourceHeight extends FieldPluginBase {
2624 * {@inheritdoc}
2725 */
2826 protected function resolveValues ($ value , array $ args , ResolveInfo $ info ) {
29- if ($ value instanceof ImageItem && $ value ->entity ->access ('view ' )) {
30- yield (int ) $ value ->height ;
31- }
32-
33- if (is_array ($ value ) && array_key_exists ('height ' , $ value )) {
34- yield (int ) $ value ['height ' ];
35- }
27+ yield (int ) $ value ['height ' ];
3628 }
3729
3830}
Original file line number Diff line number Diff line change 1515 * name = "url",
1616 * type = "String",
1717 * parents = {"ImageResource"},
18- * field_types = {"image"},
19- * provider = "image",
20- * deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
18+ * provider = "image"
2119 * )
2220 */
2321class ImageResourceUrl extends FieldPluginBase {
@@ -26,13 +24,7 @@ class ImageResourceUrl extends FieldPluginBase {
2624 * {@inheritdoc}
2725 */
2826 protected function resolveValues ($ value , array $ args , ResolveInfo $ info ) {
29- if ($ value instanceof ImageItem && $ value ->entity ->access ('view ' )) {
30- yield file_create_url ($ value ->entity ->getFileUri ());
31- }
32-
33- if (is_array ($ value ) && array_key_exists ('url ' , $ value )) {
34- yield $ value ['url ' ];
35- }
27+ yield $ value ['url ' ];
3628 }
3729
3830}
Original file line number Diff line number Diff line change 1414 * secure = true,
1515 * name = "width",
1616 * type = "Int",
17- * provider = "image",
1817 * parents = {"ImageResource"},
19- * field_types = {"image"},
20- * deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver"
18+ * provider = "image"
2119 * )
2220 */
2321class ImageResourceWidth extends FieldPluginBase {
@@ -26,13 +24,7 @@ class ImageResourceWidth extends FieldPluginBase {
2624 * {@inheritdoc}
2725 */
2826 protected function resolveValues ($ value , array $ args , ResolveInfo $ info ) {
29- if ($ value instanceof ImageItem && $ value ->entity ->access ('view ' )) {
30- yield (int ) $ value ->width ;
31- }
32-
33- if (is_array ($ value ) && array_key_exists ('width ' , $ value )) {
34- yield (int ) $ value ['width ' ];
35- }
27+ yield (int ) $ value ['width ' ];
3628 }
3729
3830}
You can’t perform that action at this time.
0 commit comments