Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EntityCmsPage.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\GoogleOptimizer\Model\Code as GoogleOptimizerCode;
11 
13 {
17  private $coreRegistry;
18 
22  private $codeModel;
23 
29  private $entity;
30 
36  public function __construct(
37  \Magento\Framework\Registry $registry,
38  GoogleOptimizerCode $code,
39  array $data = []
40  ) {
41  $this->coreRegistry = $registry;
42  $this->codeModel = $code;
43  parent::__construct($data);
44  }
45 
52  public function getCode()
53  {
54  $code = null;
55  $entity = $this->getEntity();
56  if ($entity->getId()) {
57  $this->codeModel->loadByEntityIdAndType($entity->getId(), GoogleOptimizerCode::ENTITY_TYPE_PAGE);
58  $code = $this->codeModel;
59  }
60  return $code;
61  }
62 
69  private function getEntity()
70  {
71  if (!$this->entity) {
72  $this->entity = $this->coreRegistry->registry('cms_page');
73  if (!$this->entity) {
74  throw new NoSuchEntityException();
75  }
76  }
77  return $this->entity;
78  }
79 }
__construct(\Magento\Framework\Registry $registry, GoogleOptimizerCode $code, array $data=[])
$code
Definition: info.phtml:12