Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ApplyBlockPersistentDataObserver.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
19 
25  protected $_customerSession;
26 
32  protected $_persistentData = null;
33 
39  protected $_persistentSession = null;
40 
47  public function __construct(
48  \Magento\Persistent\Helper\Session $persistentSession,
49  \Magento\Persistent\Helper\Data $persistentData,
50  \Magento\Customer\Model\Session $customerSession,
51  \Magento\Persistent\Model\Persistent\ConfigFactory $persistentConfigFactory
52  ) {
53  $this->_persistentSession = $persistentSession;
54  $this->_persistentData = $persistentData;
55  $this->_customerSession = $customerSession;
56  $this->_persistentConfigFactory = $persistentConfigFactory;
57  }
58 
65  public function execute(\Magento\Framework\Event\Observer $observer)
66  {
67  if (!$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
68  return $this;
69  }
70 
72  $block = $observer->getEvent()->getBlock();
73 
74  if (!$block) {
75  return $this;
76  }
77 
78  $configFilePath = $observer->getEvent()->getConfigFilePath();
79  if (!$configFilePath) {
80  $configFilePath = $this->_persistentData->getPersistentConfigFilePath();
81  }
82 
84  $persistentConfig = $this->_persistentConfigFactory->create();
85  $persistentConfig->setConfigFilePath($configFilePath);
86 
87  foreach ($persistentConfig->getBlockConfigInfo(get_class($block)) as $persistentConfigInfo) {
88  $persistentConfig->fireOne($persistentConfigInfo, $block);
89  }
90 
91  return $this;
92  }
93 }
$block
Definition: block.php:8
$persistentSession
Definition: persistent.php:11
__construct(\Magento\Persistent\Helper\Session $persistentSession, \Magento\Persistent\Helper\Data $persistentData, \Magento\Customer\Model\Session $customerSession, \Magento\Persistent\Model\Persistent\ConfigFactory $persistentConfigFactory)