Dump.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Model\Design\Config\Plugin;
  7. use Magento\Config\App\Config\Source\DumpConfigSourceAggregated;
  8. use Magento\Framework\Stdlib\ArrayManager;
  9. use Magento\Framework\View\Design\Theme\ListInterface;
  10. use Magento\Framework\View\DesignInterface;
  11. /**
  12. * This is plugin for Magento\Config\App\Config\Source\DumpConfigSourceAggregated class.
  13. *
  14. * Detects the design theme configuration data (path \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID)
  15. * and convert theme identifier from theme_id to theme_full_path.
  16. * As a result of Magento\Config\App\Config\Source\DumpConfigSourceAggregated expected
  17. * to be shared between environments where IDs can not be used, we need
  18. * to change theme id to full path value what can be used as an identifier.
  19. * @see \Magento\Config\App\Config\Source\DumpConfigSourceAggregated
  20. */
  21. class Dump
  22. {
  23. /**
  24. * @var ListInterface
  25. */
  26. private $themeList;
  27. /**
  28. * @var ArrayManager
  29. */
  30. private $arrayManager;
  31. /**
  32. * @param ListInterface $themeList
  33. * @param ArrayManager $arrayManager
  34. */
  35. public function __construct(
  36. ListInterface $themeList,
  37. ArrayManager $arrayManager
  38. ) {
  39. $this->themeList = $themeList;
  40. $this->arrayManager = $arrayManager;
  41. }
  42. /**
  43. * Change value from theme_id field to full path for every existed scope.
  44. * All other values leave without changes.
  45. *
  46. * @param DumpConfigSourceAggregated $subject
  47. * @param array $result
  48. * @return array
  49. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  50. */
  51. public function afterGet(DumpConfigSourceAggregated $subject, $result)
  52. {
  53. foreach ($result as $scope => &$item) {
  54. if ($scope === \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
  55. $item = $this->changeThemeIdToFullPath($item);
  56. } else {
  57. foreach ($item as &$scopeItems) {
  58. $scopeItems = $this->changeThemeIdToFullPath($scopeItems);
  59. }
  60. }
  61. }
  62. return $result;
  63. }
  64. /**
  65. * Check \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID config path
  66. * and convert theme_id to full_theme_path. Ex. "frontend/Magento/blank"
  67. *
  68. * @param array $configItems
  69. * @return array
  70. */
  71. private function changeThemeIdToFullPath($configItems)
  72. {
  73. $theme = null;
  74. if ($this->arrayManager->exists(DesignInterface::XML_PATH_THEME_ID, $configItems)) {
  75. $themeIdentifier = $this->arrayManager->get(DesignInterface::XML_PATH_THEME_ID, $configItems);
  76. if (is_numeric($themeIdentifier)) {
  77. $theme = $this->themeList->getItemById($themeIdentifier);
  78. }
  79. if ($theme && $theme->getFullPath()) {
  80. return $this->arrayManager->set(
  81. DesignInterface::XML_PATH_THEME_ID,
  82. $configItems,
  83. $theme->getFullPath()
  84. );
  85. }
  86. }
  87. return $configItems;
  88. }
  89. }