Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Page.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
21 class Page implements ResolverInterface
22 {
26  private $pageDataProvider;
27 
31  public function __construct(
32  PageDataProvider $pageDataProvider
33  ) {
34  $this->pageDataProvider = $pageDataProvider;
35  }
36 
40  public function resolve(
41  Field $field,
42  $context,
44  array $value = null,
45  array $args = null
46  ) {
47  $pageId = $this->getPageId($args);
48  $pageData = $this->getPageData($pageId);
49 
50  return $pageData;
51  }
52 
58  private function getPageId(array $args): int
59  {
60  if (!isset($args['id'])) {
61  throw new GraphQlInputException(__('"Page id should be specified'));
62  }
63 
64  return (int)$args['id'];
65  }
66 
72  private function getPageData(int $pageId): array
73  {
74  try {
75  $pageData = $this->pageDataProvider->getData($pageId);
76  } catch (NoSuchEntityException $e) {
77  throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
78  }
79  return $pageData;
80  }
81 }
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
Definition: Page.php:40
__()
Definition: __.php:13
$value
Definition: gender.phtml:16
__construct(PageDataProvider $pageDataProvider)
Definition: Page.php:31
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52