Skip to content

Commit a18a087

Browse files
author
vitaliyboyko
committed
graphQl-44: added html content resolver
1 parent 80669e3 commit a18a087

File tree

6 files changed

+61
-212
lines changed

6 files changed

+61
-212
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatInterface.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatList.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/Html.php

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\Catalog\Helper\Output as OutputHelper;
15+
16+
/**
17+
* HTML content of Product Text Attribute
18+
*/
19+
class HtmlContent implements ResolverInterface
20+
{
21+
/**
22+
* @var OutputHelper
23+
*/
24+
private $outputHelper;
25+
26+
/**
27+
* @param OutputHelper $outputHelper
28+
*/
29+
public function __construct(
30+
OutputHelper $outputHelper
31+
) {
32+
$this->outputHelper = $outputHelper;
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function resolve(
39+
Field $field,
40+
$context,
41+
ResolveInfo $info,
42+
array $value = null,
43+
array $args = null
44+
): array {
45+
if (!isset($value['model'])) {
46+
return [];
47+
}
48+
49+
/* @var $product Product */
50+
$product = $value['model'];
51+
$fieldName = $field->getName();
52+
$renderedValue = $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName);
53+
54+
return $renderedValue;
55+
}
56+
}

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
248248
id: Int @doc(description: "The ID number assigned to the product") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\EntityIdToId")
249249
name: String @doc(description: "The product name. Customers use this name to identify the product.")
250250
sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer")
251-
description: ProductTextAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute")
252-
short_description: ProductTextAttribute @doc(description: "A short description of the product. Its use depends on the theme.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute")
251+
description: ProductTextAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
252+
short_description: ProductTextAttribute @doc(description: "A short description of the product. Its use depends on the theme.")
253253
special_price: Float @doc(description: "The discounted price of the product")
254254
special_from_date: String @doc(description: "The beginning date that a product has a special price")
255255
special_to_date: String @doc(description: "The end date that a product has a special price")
@@ -433,8 +433,8 @@ type CategoryProducts @doc(description: "The category products object returned i
433433
input ProductFilterInput @doc(description: "ProductFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") {
434434
name: FilterTypeInput @doc(description: "The product name. Customers use this name to identify the product.")
435435
sku: FilterTypeInput @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer")
436-
description: ProductTextAttributeTypeInput @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
437-
short_description: ProductTextAttributeTypeInput @doc(description: "A short description of the product. Its use depends on the theme.")
436+
description: FilterTypeInput @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
437+
short_description: FilterTypeInput @doc(description: "A short description of the product. Its use depends on the theme.")
438438
price: FilterTypeInput @doc(description: "The price of an item")
439439
special_price: FilterTypeInput @doc(description: "The discounted price of the product")
440440
special_from_date: FilterTypeInput @doc(description: "The beginning date that a product has a special price")
@@ -558,24 +558,5 @@ type SortFields @doc(description: "SortFields contains a default value for sort
558558
}
559559

560560
type ProductTextAttribute @doc(description: "Product text attribute.") {
561-
content: String
562-
}
563-
564-
input ProductTextAttributeTypeInput @doc(description: "FilterTypeInput specifies which action will be performed in a query ") {
565-
format: String @doc(description: "Format of the content")
566-
eq: String @doc(description: "Equals")
567-
finset: [String] @doc(description: "Find in set. The value can contain a set of comma-separated values")
568-
from: String @doc(description: "From. Must be used with 'to'")
569-
gt: String @doc(description: "Greater than")
570-
gteq: String @doc(description: "Greater than or equal to")
571-
in: [String] @doc(description: "In. The value can contain a set of comma-separated values")
572-
like: String @doc(description: "Like. The specified value can contain % (percent signs) to allow matching of 0 or more characters")
573-
lt: String @doc(description: "Less than")
574-
lteq: String @doc(description: "Less than or equal to")
575-
moreq: String @doc(description: "More than or equal to")
576-
neq: String @doc(description: "Not equal to")
577-
notnull: String @doc(description: "Not null")
578-
null: String @doc(description: "Is null")
579-
to: String@doc(description: "To. Must be used with 'from'")
580-
nin: [String] @doc(description: "Not in. The value can contain a set of comma-separated values")
561+
html: String @doc(description: "Attribute HTML content") @resolver(class: "\\Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute\\HtmlContent")
581562
}

0 commit comments

Comments
 (0)