-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render category description directives
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CategoryHtmlAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Category; | ||
|
||
use Magento\Catalog\Model\Category; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\Resolver\Value; | ||
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Catalog\Helper\Output as OutputHelper; | ||
|
||
/** | ||
* Resolve rendered content for category attributes where HTML content is allowed | ||
*/ | ||
class CategoryHtmlAttribute implements ResolverInterface | ||
{ | ||
/** | ||
* @var ValueFactory | ||
*/ | ||
private $valueFactory; | ||
|
||
/** | ||
* @var OutputHelper | ||
*/ | ||
private $outputHelper; | ||
|
||
/** | ||
* @param ValueFactory $valueFactory | ||
* @param OutputHelper $outputHelper | ||
*/ | ||
public function __construct( | ||
ValueFactory $valueFactory, | ||
OutputHelper $outputHelper | ||
) { | ||
$this->valueFactory = $valueFactory; | ||
$this->outputHelper = $outputHelper; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
): Value { | ||
if (!isset($value['model'])) { | ||
$result = function () { | ||
return null; | ||
}; | ||
return $this->valueFactory->create($result); | ||
} | ||
|
||
/* @var $category Category */ | ||
$category = $value['model']; | ||
$fieldName = $field->getName(); | ||
$renderedValue = $this->outputHelper->categoryAttribute($category, $category->getData($fieldName), $fieldName); | ||
|
||
$result = function () use ($renderedValue) { | ||
return $renderedValue; | ||
}; | ||
|
||
return $this->valueFactory->create($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters