Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Options.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
18 
22 class Options implements ResolverInterface
23 {
27  private $optionCollection;
28 
32  private $valueFactory;
33 
37  private $metadataPool;
38 
44  public function __construct(
45  OptionCollection $optionCollection,
46  ValueFactory $valueFactory,
47  MetadataPool $metadataPool
48  ) {
49  $this->optionCollection = $optionCollection;
50  $this->valueFactory = $valueFactory;
51  $this->metadataPool = $metadataPool;
52  }
53 
59  public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
60  {
61  $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
62  if ($value['type_id'] !== Type::TYPE_CODE || !isset($value[$linkField])) {
63  $result = function () {
64  return null;
65  };
66  return $this->valueFactory->create($result);
67  }
68 
69  $this->optionCollection->addProductId((int)$value[$linkField]);
70 
71  $result = function () use ($value, $linkField) {
72  return $this->optionCollection->getAttributesByProductId((int)$value[$linkField]);
73  };
74 
75  return $this->valueFactory->create($result);
76  }
77 }
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
Definition: Options.php:59
$value
Definition: gender.phtml:16
__construct(OptionCollection $optionCollection, ValueFactory $valueFactory, MetadataPool $metadataPool)
Definition: Options.php:44
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52