Resolver.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Model\Theme;
  7. /**
  8. * Theme resolver model
  9. */
  10. class Resolver implements \Magento\Framework\View\Design\Theme\ResolverInterface
  11. {
  12. /**
  13. * @var \Magento\Framework\View\DesignInterface
  14. */
  15. protected $design;
  16. /**
  17. * @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory
  18. */
  19. protected $themeFactory;
  20. /**
  21. * @var \Magento\Framework\App\State
  22. */
  23. protected $appState;
  24. /**
  25. * @param \Magento\Framework\App\State $appState
  26. * @param \Magento\Framework\View\DesignInterface $design
  27. * @param \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $themeFactory
  28. */
  29. public function __construct(
  30. \Magento\Framework\App\State $appState,
  31. \Magento\Framework\View\DesignInterface $design,
  32. \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $themeFactory
  33. ) {
  34. $this->design = $design;
  35. $this->themeFactory = $themeFactory;
  36. $this->appState = $appState;
  37. }
  38. /**
  39. * Retrieve instance of a theme currently used in an area
  40. *
  41. * @return \Magento\Framework\View\Design\ThemeInterface
  42. */
  43. public function get()
  44. {
  45. $area = $this->appState->getAreaCode();
  46. if ($this->design->getDesignTheme()->getArea() == $area || $this->design->getArea() == $area) {
  47. return $this->design->getDesignTheme();
  48. }
  49. /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */
  50. $themeCollection = $this->themeFactory->create();
  51. $themeIdentifier = $this->design->getConfigurationDesignTheme($area);
  52. if (is_numeric($themeIdentifier)) {
  53. $result = $themeCollection->getItemById($themeIdentifier);
  54. } else {
  55. $themeFullPath = $area . \Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR . $themeIdentifier;
  56. $result = $themeCollection->getThemeByFullPath($themeFullPath);
  57. }
  58. return $result;
  59. }
  60. }