85 private $themeModelFactory;
117 ThemeCollection $resourceCollection =
null,
119 ThemeFactory $themeModelFactory =
null 122 $this->_themeFactory = $themeFactory;
123 $this->_domainFactory = $domainFactory;
124 $this->_imageFactory = $imageFactory;
125 $this->_validator = $validator;
126 $this->_customFactory = $customizationFactory;
128 $this->
addData([
'type' => self::TYPE_VIRTUAL]);
148 return $this->_imageFactory->create([
'theme' => $this]);
156 if ($this->_customization ===
null) {
157 $this->_customization = $this->_customFactory->create([
'theme' => $this]);
179 return self::TYPE_PHYSICAL != $this->getType();
209 return in_array($this->getType(), [self::TYPE_PHYSICAL, self::TYPE_VIRTUAL]);
223 [
'eq' => $this->
getId()]
234 if ($this->
getId()) {
237 $collection->addFieldToFilter(
'type', self::TYPE_STAGING);
239 if ($stagingTheme->getId()) {
240 return $stagingTheme;
251 if ($this->
hasData(
'parent_theme')) {
252 return $this->
getData(
'parent_theme');
256 if ($this->getParentId()) {
257 $theme = $this->_themeFactory->create($this->getParentId());
259 $this->setParentTheme(
$theme);
269 if ($this->
getData(
'area') && !$this->_appState->isAreaCodeEmulated()) {
272 return $this->_appState->getAreaCode();
280 return $this->
getData(
'theme_path');
301 return (
string)$this->
getData(
'code');
313 if (
$type !==
null &&
$type != $this->getType()) {
314 throw new \InvalidArgumentException(
316 'Invalid domain model "%s" requested for theme "%s" of type "%s"',
324 return $this->_domainFactory->create($this);
335 if (!$this->_validator->validate($this)) {
336 $messages = $this->_validator->getErrorMessages();
337 throw new \Magento\Framework\Exception\LocalizedException(
__(implode(PHP_EOL, reset($messages))));
350 return parent::beforeSave();
361 if ($stagingVersion) {
362 $stagingVersion->delete();
365 return parent::afterDelete();
375 if (
null === $this->inheritanceSequence) {
382 $this->inheritanceSequence = array_reverse(
$result);
392 $data = parent::toArray($keys);
393 if (isset(
$data[
'parent_theme'])) {
397 if (isset(
$data[
'inherited_themes'])) {
398 foreach (
$data[
'inherited_themes'] as $key => $inheritedTheme) {
399 $data[
'inherited_themes'][$key] = $inheritedTheme->toArray();
414 $this->_data =
$data;
415 if (isset(
$data[
'parent_theme'])) {
416 $this->_data[
'parent_theme'] = $this->createThemeInstance()->populateFromArray(
$data[
'parent_theme']);
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;
434 private function createThemeInstance()
436 return $this->themeModelFactory->create();
__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)
getData($key='', $index=null)
getDomainModel($type=null)
populateFromArray(array $data)