Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Theme Class Reference
Inheritance diagram for Theme:
AbstractModel ThemeInterface DataObject Data

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory, \Magento\Framework\View\Design\Theme\Domain\Factory $domainFactory, \Magento\Framework\View\Design\Theme\ImageFactory $imageFactory, \Magento\Framework\View\Design\Theme\Validator $validator, \Magento\Framework\View\Design\Theme\CustomizationFactory $customizationFactory, \Magento\Theme\Model\ResourceModel\Theme $resource=null, ThemeCollection $resourceCollection=null, array $data=[], ThemeFactory $themeModelFactory=null)
 
 getThemeImage ()
 
 getCustomization ()
 
 isDeletable ()
 
 isEditable ()
 
 isVirtual ()
 
 isPhysical ()
 
 isVisible ()
 
 hasChildThemes ()
 
 getStagingVersion ()
 
 getParentTheme ()
 
 getArea ()
 
 getThemePath ()
 
 getFullPath ()
 
 getCode ()
 
 getDomainModel ($type=null)
 
 beforeSave ()
 
 afterDelete ()
 
 getInheritedThemes ()
 
 toArray (array $keys=[])
 
 populateFromArray (array $data)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from ThemeInterface
 getId ()
 

Protected Member Functions

 _construct ()
 
 _validate ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventPrefix = 'theme'
 
 $_eventObject = 'theme'
 
 $_themeFactory
 
 $_domainFactory
 
 $_imageFactory
 
 $_validator
 
 $_customization
 
 $_customFactory
 
 $inheritanceSequence
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Data Fields inherited from ThemeInterface
const PATH_SEPARATOR = '/'
 
const CODE_SEPARATOR = '/'
 
const TYPE_PHYSICAL = 0
 
const TYPE_VIRTUAL = 1
 
const TYPE_STAGING = 2
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Theme model class

@method string getPackageCode() @method string getParentThemePath() @method string getParentId() @method string getThemeTitle() @method string getPreviewImage() @method bool getIsFeatured() @method int getThemeId() @method int getType() @method array getAssignedStores() @method ThemeInterface setAssignedStores(array $stores) @method ThemeInterface setParentId(int $id) @method ThemeInterface setParentTheme($parentTheme) @method ThemeInterface setPackageCode(string $packageCode) @method ThemeInterface setThemeCode(string $themeCode) @method ThemeInterface setThemePath(string $themePath) @method ThemeInterface setThemeTitle(string $themeTitle) @method ThemeInterface setType(int $type) @method ThemeInterface setCode(string $code)

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 36 of file Theme.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\View\Design\Theme\FlyweightFactory  $themeFactory,
\Magento\Framework\View\Design\Theme\Domain\Factory  $domainFactory,
\Magento\Framework\View\Design\Theme\ImageFactory  $imageFactory,
\Magento\Framework\View\Design\Theme\Validator  $validator,
\Magento\Framework\View\Design\Theme\CustomizationFactory  $customizationFactory,
\Magento\Theme\Model\ResourceModel\Theme  $resource = null,
ThemeCollection  $resourceCollection = null,
array  $data = [],
ThemeFactory  $themeModelFactory = null 
)

Initialize dependencies

Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\View\Design\Theme\FlyweightFactory$themeFactory
\Magento\Framework\View\Design\Theme\Domain\Factory$domainFactory
\Magento\Framework\View\Design\Theme\ImageFactory$imageFactory
\Magento\Framework\View\Design\Theme\Validator$validator
\Magento\Framework\View\Design\Theme\CustomizationFactory$customizationFactory
\Magento\Theme\Model\ResourceModel\Theme$resource
\Magento\Theme\Model\ResourceModel\Theme\Collection$resourceCollection
array$data
ThemeFactory$themeModelFactory@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 108 of file Theme.php.

120  {
121  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
122  $this->_themeFactory = $themeFactory;
123  $this->_domainFactory = $domainFactory;
124  $this->_imageFactory = $imageFactory;
125  $this->_validator = $validator;
126  $this->_customFactory = $customizationFactory;
127  $this->themeModelFactory = $themeModelFactory ?: ObjectManager::getInstance()->get(ThemeFactory::class);
128  $this->addData(['type' => self::TYPE_VIRTUAL]);
129  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected

Init resource model

Returns
void

Definition at line 136 of file Theme.php.

137  {
138  $this->_init(\Magento\Theme\Model\ResourceModel\Theme::class);
139  }

◆ _validate()

_validate ( )
protected

Validate theme data

Returns
$this
Exceptions

Definition at line 333 of file Theme.php.

334  {
335  if (!$this->_validator->validate($this)) {
336  $messages = $this->_validator->getErrorMessages();
337  throw new \Magento\Framework\Exception\LocalizedException(__(implode(PHP_EOL, reset($messages))));
338  }
339  return $this;
340  }
__()
Definition: __.php:13

◆ afterDelete()

afterDelete ( )

Update all relations after deleting theme

Returns
$this

Definition at line 358 of file Theme.php.

359  {
360  $stagingVersion = $this->getStagingVersion();
361  if ($stagingVersion) {
362  $stagingVersion->delete();
363  }
364  $this->getCollection()->updateChildRelations($this);
365  return parent::afterDelete();
366  }

◆ beforeSave()

beforeSave ( )

Before theme save

Returns
$this

Definition at line 347 of file Theme.php.

348  {
349  $this->_validate();
350  return parent::beforeSave();
351  }

◆ getArea()

getArea ( )

{Retrieve code of an area a theme belongs to

Returns
string
}

Implements ThemeInterface.

Definition at line 266 of file Theme.php.

267  {
268  // In order to support environment emulation of area, if area is set, return it
269  if ($this->getData('area') && !$this->_appState->isAreaCodeEmulated()) {
270  return $this->getData('area');
271  }
272  return $this->_appState->getAreaCode();
273  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getCode()

getCode ( )

{Get code of the theme

Returns
string
}

Implements ThemeInterface.

Definition at line 299 of file Theme.php.

300  {
301  return (string)$this->getData('code');
302  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getCustomization()

getCustomization ( )
Returns
\Magento\Framework\View\Design\Theme\Customization

Definition at line 154 of file Theme.php.

155  {
156  if ($this->_customization === null) {
157  $this->_customization = $this->_customFactory->create(['theme' => $this]);
158  }
159  return $this->_customization;
160  }

◆ getDomainModel()

getDomainModel (   $type = null)

Get one of theme domain models

Parameters
int | null$type
Returns
\Magento\Theme\Model\Theme\Domain\Virtual|\Magento\Theme\Model\Theme\Domain\Staging
Exceptions

Definition at line 311 of file Theme.php.

312  {
313  if ($type !== null && $type != $this->getType()) {
314  throw new \InvalidArgumentException(
315  sprintf(
316  'Invalid domain model "%s" requested for theme "%s" of type "%s"',
317  $type,
318  $this->getId(),
319  $this->getType()
320  )
321  );
322  }
323 
324  return $this->_domainFactory->create($this);
325  }
$type
Definition: item.phtml:13

◆ getFullPath()

getFullPath ( )

Retrieve theme full path which is used to distinguish themes if they are not in DB yet

Alternative id looks like "<area>/<theme_path>". Used as id in file-system theme collection

Returns
string|null

Implements ThemeInterface.

Definition at line 291 of file Theme.php.

292  {
293  return $this->getThemePath() ? $this->getArea() . self::PATH_SEPARATOR . $this->getThemePath() : null;
294  }

◆ getInheritedThemes()

getInheritedThemes ( )

Return the full theme inheritance sequence, from the root theme till a specified one

Returns
ThemeInterface[]

Implements ThemeInterface.

Definition at line 373 of file Theme.php.

374  {
375  if (null === $this->inheritanceSequence) {
376  $theme = $this;
377  $result = [];
378  while ($theme) {
379  $result[] = $theme;
380  $theme = $theme->getParentTheme();
381  }
382  $this->inheritanceSequence = array_reverse($result);
383  }
385  }
$theme

◆ getParentTheme()

getParentTheme ( )

{Retrieve parent theme instance

Returns
ThemeInterface|null
}

Implements ThemeInterface.

Definition at line 249 of file Theme.php.

250  {
251  if ($this->hasData('parent_theme')) {
252  return $this->getData('parent_theme');
253  }
254 
255  $theme = null;
256  if ($this->getParentId()) {
257  $theme = $this->_themeFactory->create($this->getParentId());
258  }
259  $this->setParentTheme($theme);
260  return $theme;
261  }
getData($key='', $index=null)
Definition: DataObject.php:119
$theme

◆ getStagingVersion()

getStagingVersion ( )

Retrieve theme instance representing the latest changes to a theme

Returns
Theme|null

Definition at line 232 of file Theme.php.

233  {
234  if ($this->getId()) {
235  $collection = $this->getCollection();
236  $collection->addFieldToFilter('parent_id', $this->getId());
237  $collection->addFieldToFilter('type', self::TYPE_STAGING);
238  $stagingTheme = $collection->getFirstItem();
239  if ($stagingTheme->getId()) {
240  return $stagingTheme;
241  }
242  }
243  return null;
244  }

◆ getThemeImage()

getThemeImage ( )

Get theme image model

Returns
\Magento\Framework\View\Design\Theme\Image

Definition at line 146 of file Theme.php.

147  {
148  return $this->_imageFactory->create(['theme' => $this]);
149  }

◆ getThemePath()

getThemePath ( )

{Retrieve theme path unique within an area

Returns
string
}

Implements ThemeInterface.

Definition at line 278 of file Theme.php.

279  {
280  return $this->getData('theme_path');
281  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ hasChildThemes()

hasChildThemes ( )

Check is theme has child virtual themes

Returns
bool

Definition at line 217 of file Theme.php.

218  {
219  return (bool)$this->getCollection()->addTypeFilter(
220  self::TYPE_VIRTUAL
221  )->addFieldToFilter(
222  'parent_id',
223  ['eq' => $this->getId()]
224  )->getSize();
225  }

◆ isDeletable()

isDeletable ( )

Check if theme is deletable

Returns
bool

Definition at line 167 of file Theme.php.

168  {
169  return $this->isEditable();
170  }

◆ isEditable()

isEditable ( )

Check if theme is editable

Returns
bool

Definition at line 177 of file Theme.php.

178  {
179  return self::TYPE_PHYSICAL != $this->getType();
180  }

◆ isPhysical()

isPhysical ( )

Check if theme is physical

Returns
bool

Implements ThemeInterface.

Definition at line 197 of file Theme.php.

198  {
199  return $this->getType() == self::TYPE_PHYSICAL;
200  }

◆ isVirtual()

isVirtual ( )

Check if theme is virtual

Returns
bool

Definition at line 187 of file Theme.php.

188  {
189  return $this->getType() == self::TYPE_VIRTUAL;
190  }

◆ isVisible()

isVisible ( )

Check theme is visible in backend

Returns
bool

Definition at line 207 of file Theme.php.

208  {
209  return in_array($this->getType(), [self::TYPE_PHYSICAL, self::TYPE_VIRTUAL]);
210  }

◆ populateFromArray()

populateFromArray ( array  $data)

Populate Theme object from an array

Parameters
array$data
Returns
Theme

Definition at line 412 of file Theme.php.

413  {
414  $this->_data = $data;
415  if (isset($data['parent_theme'])) {
416  $this->_data['parent_theme'] = $this->createThemeInstance()->populateFromArray($data['parent_theme']);
417  }
418 
419  if (isset($data['inherited_themes'])) {
420  foreach ($data['inherited_themes'] as $key => $inheritedTheme) {
421  $themeInstance = $this->createThemeInstance()->populateFromArray($inheritedTheme);
422  $this->_data['inherited_themes'][$key] = $themeInstance;
423  }
424  }
425 
426  return $this;
427  }

◆ toArray()

toArray ( array  $keys = [])

Definition at line 390 of file Theme.php.

391  {
392  $data = parent::toArray($keys);
393  if (isset($data['parent_theme'])) {
394  $data['parent_theme'] = $this->getParentTheme()->toArray();
395  }
396 
397  if (isset($data['inherited_themes'])) {
398  foreach ($data['inherited_themes'] as $key => $inheritedTheme) {
399  $data['inherited_themes'][$key] = $inheritedTheme->toArray();
400  }
401  }
402 
403  return $data;
404  }

Field Documentation

◆ $_customFactory

$_customFactory
protected

Definition at line 80 of file Theme.php.

◆ $_customization

$_customization
protected

Definition at line 75 of file Theme.php.

◆ $_domainFactory

$_domainFactory
protected

Definition at line 60 of file Theme.php.

◆ $_eventObject

$_eventObject = 'theme'
protected

Definition at line 50 of file Theme.php.

◆ $_eventPrefix

$_eventPrefix = 'theme'
protected

Definition at line 43 of file Theme.php.

◆ $_imageFactory

$_imageFactory
protected

Definition at line 65 of file Theme.php.

◆ $_themeFactory

$_themeFactory
protected

Definition at line 55 of file Theme.php.

◆ $_validator

$_validator
protected

Definition at line 70 of file Theme.php.

◆ $inheritanceSequence

$inheritanceSequence
protected

Definition at line 90 of file Theme.php.


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