coreRegistry = $registry; $this->codeModel = $code; parent::__construct($data); } /** * Returns Code Model * * @return GoogleOptimizerCode|null * @throws NoSuchEntityException */ public function getCode() { $code = null; $entity = $this->getEntity(); if ($entity->getId()) { $this->codeModel->loadByEntityIdAndType($entity->getId(), GoogleOptimizerCode::ENTITY_TYPE_PAGE); $code = $this->codeModel; } return $code; } /** * Retrieves Google Optimizer binded entity * * @return \Magento\Cms\Model\Page|mixed * @throws NoSuchEntityException */ private function getEntity() { if (!$this->entity) { $this->entity = $this->coreRegistry->registry('cms_page'); if (!$this->entity) { throw new NoSuchEntityException(); } } return $this->entity; } }