Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Code Class Reference

Public Member Functions

 __construct (\Magento\GoogleOptimizer\Model\Code $code)
 
 getCodeObjectByEntity (\Magento\Framework\Model\AbstractModel $entity)
 

Protected Member Functions

 _getEntityType ()
 
 _getTypeString ()
 
 _checkEntityIsEmpty ()
 

Protected Attributes

 $_codeModel
 
 $_entity
 

Detailed Description

@api

Since
100.0.2

Definition at line 14 of file Code.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\GoogleOptimizer\Model\Code  $code)
Parameters
\Magento\GoogleOptimizer\Model\Code$code

Definition at line 29 of file Code.php.

30  {
31  $this->_codeModel = $code;
32  }
$code
Definition: info.phtml:12

Member Function Documentation

◆ _checkEntityIsEmpty()

_checkEntityIsEmpty ( )
protected

Check if Entity is Empty

Returns
$this
Exceptions

Definition at line 99 of file Code.php.

100  {
101  if (!$this->_entity->getId()) {
102  throw new \InvalidArgumentException('The model is empty');
103  }
104  return $this;
105  }

◆ _getEntityType()

_getEntityType ( )
protected

Get Entity Type by Entity object

Returns
string
Exceptions

Definition at line 60 of file Code.php.

61  {
62  $type = $this->_getTypeString();
63 
64  if (empty($type)) {
65  throw new \InvalidArgumentException('The model class is not valid');
66  }
67 
68  return $type;
69  }
$type
Definition: item.phtml:13

◆ _getTypeString()

_getTypeString ( )
protected

Get Entity Type string

Returns
string

Definition at line 76 of file Code.php.

77  {
78  $type = '';
79  if ($this->_entity instanceof \Magento\Catalog\Model\Category) {
81  }
82 
83  if ($this->_entity instanceof \Magento\Catalog\Model\Product) {
85  }
86 
87  if ($this->_entity instanceof \Magento\Cms\Model\Page) {
89  }
90  return $type;
91  }
$type
Definition: item.phtml:13

◆ getCodeObjectByEntity()

getCodeObjectByEntity ( \Magento\Framework\Model\AbstractModel  $entity)

Get loaded Code object by Entity

Parameters
\Magento\Framework\Model\AbstractModel$entity
Returns
\Magento\GoogleOptimizer\Model\Code

Definition at line 40 of file Code.php.

41  {
42  $this->_entity = $entity;
43 
44  $this->_checkEntityIsEmpty();
45  if ($entity instanceof \Magento\Cms\Model\Page) {
46  $this->_codeModel->loadByEntityIdAndType($entity->getId(), $this->_getEntityType());
47  } else {
48  $this->_codeModel->loadByEntityIdAndType($entity->getId(), $this->_getEntityType(), $entity->getStoreId());
49  }
50 
51  return $this->_codeModel;
52  }
$entity
Definition: element.phtml:22

Field Documentation

◆ $_codeModel

$_codeModel
protected

Definition at line 19 of file Code.php.

◆ $_entity

$_entity
protected

Definition at line 24 of file Code.php.


The documentation for this class was generated from the following file: