Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Customization.php
Go to the documentation of this file.
1 <?php
7 
12 {
18  protected $fileProvider;
19 
25  protected $customizationPath;
26 
32  protected $theme;
33 
39  protected $themeFiles;
40 
46  protected $themeFilesByType = [];
47 
55  public function __construct(
56  \Magento\Framework\View\Design\Theme\FileProviderInterface $fileProvider,
57  \Magento\Framework\View\Design\Theme\Customization\Path $customizationPath,
58  \Magento\Framework\View\Design\ThemeInterface $theme = null
59  ) {
60  $this->fileProvider = $fileProvider;
61  $this->customizationPath = $customizationPath;
62  $this->theme = $theme;
63  }
64 
70  public function getFiles()
71  {
72  if (!$this->themeFiles) {
73  $this->themeFiles = $this->fileProvider->getItems($this->theme);
74  }
75  return $this->themeFiles;
76  }
77 
84  public function getFilesByType($type)
85  {
86  if (!isset($this->themeFilesByType[$type])) {
87  $this->themeFilesByType[$type] = $this->fileProvider->getItems($this->theme, ['file_type' => $type]);
88  }
89  return $this->themeFilesByType[$type];
90  }
91 
98  public function generateFileInfo(array $files)
99  {
100  $filesInfo = [];
102  foreach ($files as $file) {
103  if ($file instanceof \Magento\Framework\View\Design\Theme\FileInterface) {
104  $filesInfo[] = $file->getFileInfo();
105  }
106  }
107  return $filesInfo;
108  }
109 
115  public function getCustomizationPath()
116  {
117  return $this->customizationPath->getCustomizationPath($this->theme);
118  }
119 
125  public function getThemeFilesPath()
126  {
127  return $this->theme->isPhysical() ? $this->customizationPath->getThemeFilesPath(
128  $this->theme
129  ) : $this->customizationPath->getCustomizationPath(
130  $this->theme
131  );
132  }
133 
139  public function getCustomViewConfigPath()
140  {
141  return $this->customizationPath->getCustomViewConfigPath($this->theme);
142  }
143 
151  public function reorder($type, array $sequence)
152  {
153  $sortOrderSequence = array_flip(array_values($sequence));
155  foreach ($this->getFilesByType($type) as $file) {
156  if (isset($sortOrderSequence[$file->getId()])) {
157  $prevSortOrder = $file->getData('sort_order');
158  $currentSortOrder = $sortOrderSequence[$file->getId()];
159  if ($prevSortOrder !== $currentSortOrder) {
160  $file->setData('sort_order', $currentSortOrder);
161  $file->save();
162  }
163  }
164  }
165  return $this;
166  }
167 
174  public function delete(array $fileIds)
175  {
177  foreach ($this->getFiles() as $file) {
178  if (in_array($file->getId(), $fileIds)) {
179  $file->delete();
180  }
181  }
182  return $this;
183  }
184 }
$type
Definition: item.phtml:13
__construct(\Magento\Framework\View\Design\Theme\FileProviderInterface $fileProvider, \Magento\Framework\View\Design\Theme\Customization\Path $customizationPath, \Magento\Framework\View\Design\ThemeInterface $theme=null)
foreach($appDirs as $dir) $files