Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Blocks.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
21 class Blocks implements ResolverInterface
22 {
26  private $blockDataProvider;
27 
31  public function __construct(
32  BlockDataProvider $blockDataProvider
33  ) {
34  $this->blockDataProvider = $blockDataProvider;
35  }
36 
40  public function resolve(
41  Field $field,
42  $context,
44  array $value = null,
45  array $args = null
46  ) {
47 
48  $blockIdentifiers = $this->getBlockIdentifiers($args);
49  $blocksData = $this->getBlocksData($blockIdentifiers);
50 
51  $resultData = [
52  'items' => $blocksData,
53  ];
54  return $resultData;
55  }
56 
62  private function getBlockIdentifiers(array $args): array
63  {
64  if (!isset($args['identifiers']) || !is_array($args['identifiers']) || count($args['identifiers']) === 0) {
65  throw new GraphQlInputException(__('"identifiers" of CMS blocks should be specified'));
66  }
67 
68  return $args['identifiers'];
69  }
70 
76  private function getBlocksData(array $blockIdentifiers): array
77  {
78  $blocksData = [];
79  try {
80  foreach ($blockIdentifiers as $blockIdentifier) {
81  $blocksData[$blockIdentifier] = $this->blockDataProvider->getData($blockIdentifier);
82  }
83  } catch (NoSuchEntityException $e) {
84  throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
85  }
86  return $blocksData;
87  }
88 }
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
Definition: Blocks.php:40
__()
Definition: __.php:13
__construct(BlockDataProvider $blockDataProvider)
Definition: Blocks.php:31
$value
Definition: gender.phtml:16
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52