Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DesignConfigRepository.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Theme\Model;
8 
16 
18 {
22  protected $reinitableConfig;
23 
27  protected $indexerRegistry;
28 
32  protected $configStorage;
33 
39  private $validator;
40 
46  public function __construct(
47  ConfigStorage $configStorage,
50  ) {
51  $this->reinitableConfig = $reinitableConfig;
52  $this->indexerRegistry = $indexerRegistry;
53  $this->configStorage = $configStorage;
54  }
55 
63  private function getValidator()
64  {
65  if (null === $this->validator) {
67  \Magento\Theme\Model\Design\Config\Validator::class
68  );
69  }
70  return $this->validator;
71  }
72 
76  public function getByScope($scope, $scopeId)
77  {
78  return $this->configStorage->load($scope, $scopeId);
79  }
80 
84  public function save(DesignConfigInterface $designConfig)
85  {
86  if (!($designConfig->getExtensionAttributes() &&
87  $designConfig->getExtensionAttributes()->getDesignConfigData())
88  ) {
89  throw new LocalizedException(
90  __("The config can't be saved because it's empty. Complete the config and try again.")
91  );
92  }
93 
94  $this->getValidator()->validate($designConfig);
95 
96  $this->configStorage->save($designConfig);
97  $this->reinitableConfig->reinit();
98  $this->reindexGrid();
99 
100  return $designConfig;
101  }
102 
106  public function delete(DesignConfigInterface $designConfig)
107  {
108  if (!($designConfig->getExtensionAttributes() &&
109  $designConfig->getExtensionAttributes()->getDesignConfigData())
110  ) {
111  throw new LocalizedException(
112  __("The config can't be saved because it's empty. Complete the config and try again.")
113  );
114  }
115 
116  $this->configStorage->delete($designConfig);
117  $this->reinitableConfig->reinit();
118  $this->reindexGrid();
119 
120  return $designConfig;
121  }
122 
128  protected function reindexGrid()
129  {
130  $this->indexerRegistry->get(DesignConfig::DESIGN_CONFIG_GRID_INDEXER_ID)->reindexAll();
131  }
132 }
__construct(ConfigStorage $configStorage, ReinitableConfigInterface $reinitableConfig, IndexerRegistry $indexerRegistry)
__()
Definition: __.php:13
save(DesignConfigInterface $designConfig)