Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
switcher.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
9 /* @var $block \Magento\Backend\Block\Store\Switcher */
10 ?>
11 <?php if ($websites = $block->getWebsites()): ?>
12 
13 <div class="store-switcher store-view">
14  <span class="store-switcher-label"><?= /* @escapeNotVerified */ __('Store View:') ?></span>
15  <div class="actions dropdown closable">
16  <input type="hidden" name="store_switcher" id="store_switcher"
17  data-role="store-view-id" data-param="<?= /* @escapeNotVerified */ $block->getStoreVarName() ?>"
18  value="<?= $block->escapeHtml($block->getStoreId()) ?>"
19  onchange="switchScope(this);"<?= /* @escapeNotVerified */ $block->getUiId() ?> />
20  <input type="hidden" name="store_group_switcher" id="store_group_switcher"
21  data-role="store-group-id" data-param="<?= /* @escapeNotVerified */ $block->getStoreGroupVarName() ?>"
22  value="<?= $block->escapeHtml($block->getStoreGroupId()) ?>"
23  onchange="switchScope(this);"<?= /* @escapeNotVerified */ $block->getUiId() ?> />
24  <input type="hidden" name="website_switcher" id="website_switcher"
25  data-role="website-id" data-param="<?= /* @escapeNotVerified */ $block->getWebsiteVarName() ?>"
26  value="<?= $block->escapeHtml($block->getWebsiteId()) ?>"
27  onchange="switchScope(this);"<?= /* @escapeNotVerified */ $block->getUiId() ?> />
28  <button
29  type="button"
30  class="admin__action-dropdown"
31  data-mage-init='{"dropdown":{}}'
32  data-toggle="dropdown"
33  aria-haspopup="true"
34  id="store-change-button">
35  <?= /* @escapeNotVerified */ $block->getCurrentSelectionName() ?>
36  </button>
37  <ul class="dropdown-menu" data-role="stores-list">
38  <?php if ($block->hasDefaultOption()): ?>
39  <li class="store-switcher-all <?php if ( ! ($block->getDefaultSelectionName() != $block->getCurrentSelectionName())) {
40  echo "disabled";
41  } ?> <?php if ( ! $block->hasScopeSelected()) {
42  ?> current<?php
43  } ?>">
44  <?php if ($block->getDefaultSelectionName() != $block->getCurrentSelectionName()) {
45  ?>
46  <a data-role="store-view-id" data-value="" href="#">
47  <?= /* @escapeNotVerified */ $block->getDefaultSelectionName() ?>
48  </a>
49  <?php
50  } else {
51  ?>
52  <span><?= /* @escapeNotVerified */ $block->getDefaultSelectionName() ?></span>
53  <?php
54  } ?>
55  </li>
56  <?php endif; ?>
57  <?php foreach ($websites as $website): ?>
58  <?php $showWebsite = false; ?>
59  <?php foreach ($website->getGroups() as $group): ?>
60  <?php $showGroup = false; ?>
61  <?php foreach ($block->getStores($group) as $store): ?>
62  <?php if ($showWebsite == false): ?>
63  <?php $showWebsite = true; ?>
64  <li class="store-switcher-website <?php if ( ! ($block->isWebsiteSwitchEnabled() && ! $block->isWebsiteSelected($website))) {
65  echo "disabled";
66  } ?> <?php if ($block->isWebsiteSelected($website)) {
67  ?> current<?php
68  } ?>">
69  <?php if ($block->isWebsiteSwitchEnabled() && ! $block->isWebsiteSelected($website)) {
70  ?>
71  <a data-role="website-id" data-value="<?= $block->escapeHtml($website->getId()) ?>" href="#">
72  <?= $block->escapeHtml($website->getName()) ?>
73  </a>
74  <?php
75  } else {
76  ?>
77  <span><?= $block->escapeHtml($website->getName()) ?></span>
78  <?php
79  } ?>
80  </li>
81  <?php endif; ?>
82  <?php if ($showGroup == false): ?>
83  <?php $showGroup = true; ?>
84  <li class="store-switcher-store <?php if ( ! ($block->isStoreGroupSwitchEnabled() && ! $block->isStoreGroupSelected($group))) {
85  echo "disabled";
86  } ?> <?php if ($block->isStoreGroupSelected($group)) {
87  ?> current<?php
88  } ?>">
89  <?php if ($block->isStoreGroupSwitchEnabled() && ! $block->isStoreGroupSelected($group)) {
90  ?>
91  <a data-role="store-group-id" data-value="<?= $block->escapeHtml($group->getId()) ?>" href="#">
92  <?= $block->escapeHtml($group->getName()) ?>
93  </a>
94  <?php
95  } else {
96  ?>
97  <span><?= $block->escapeHtml($group->getName()) ?></span>
98  <?php
99  } ?>
100  </li>
101  <?php endif; ?>
102  <li class="store-switcher-store-view <?php if ( ! ($block->isStoreSwitchEnabled() && ! $block->isStoreSelected($store))) {
103  echo "disabled";
104  } ?> <?php if ($block->isStoreSelected($store)) {
105  ?> current<?php
106  } ?>">
107  <?php if ($block->isStoreSwitchEnabled() && ! $block->isStoreSelected($store)) {
108  ?>
109  <a data-role="store-view-id" data-value="<?= $block->escapeHtml($store->getId()) ?>" href="#">
110  <?= $block->escapeHtml($store->getName()) ?>
111  </a>
112  <?php
113  } else {
114  ?>
115  <span><?= $block->escapeHtml($store->getName()) ?></span>
116  <?php
117  } ?>
118  </li>
119  <?php endforeach; ?>
120  <?php endforeach; ?>
121  <?php endforeach; ?>
122  <?php if ($block->getShowManageStoresLink() && $block->getAuthorization()->isAllowed('Magento_Backend::store')): ?>
123  <li class="dropdown-toolbar">
124  <a href="<?= /* @escapeNotVerified */ $block->getUrl('*/system_store') ?>"><?= /* @escapeNotVerified */ __('Stores Configuration') ?></a>
125  </li>
126  <?php endif; ?>
127  </ul>
128  </div>
129  <?= $block->getHintHtml() ?>
130 </div>
131 
132 <script>
133 require([
134  'jquery',
135  'Magento_Ui/js/modal/confirm'
136 ], function(jQuery, confirm){
137 
138  (function($) {
139  var $storesList = $('[data-role=stores-list]');
140  $storesList.on('click', '[data-value]', function(event) {
141  var val = $(event.target).data('value');
142  var role = $(event.target).data('role');
143  var switcher = $('[data-role='+role+']');
144 
145  event.preventDefault();
146 
147  if (!switcher.val() || val != switcher.val()) {
148  switcher.val(val).trigger('change'); // Set the value & trigger event
149  }
150  });
151  })(jQuery);
152 
153  var scopeSwitcherHandler;
154 
155  function switchScope(obj) {
156  var switcher = jQuery(obj);
157  var scopeId = switcher.val();
158  var scopeParams = '';
159  if (scopeId) {
160  scopeParams = switcher.data('param') + '/' + scopeId + '/';
161  }
162 
163  if (obj.switchParams) {
164  scopeParams += obj.switchParams;
165  }
166 
167  if ((typeof scopeSwitcherHandler) != 'undefined') {
168  var switcherParams = {
169  scopeId: scopeId,
170  scopeParams: scopeParams,
171  useConfirm: <?= (int)$block->getUseConfirm() ?>
172  };
173  scopeSwitcherHandler(switcherParams);
174  } else {
175 
176  <?php if ($block->getUseConfirm()): ?>
177 
178  confirm({
179  content: "<?= /* @escapeNotVerified */ __('Please confirm scope switching. All data that hasn\'t been saved will be lost.') ?>",
180  actions: {
181  confirm: function() {
182  reload();
183  },
184  cancel: function() {
185  obj.value = '<?= $block->escapeHtml($block->getStoreId()) ?>';
186  }
187  }
188  });
189 
190  <?php else: ?>
191  reload();
192  <?php endif; ?>
193  }
194 
195  function reload() {
196  <?php if (!$block->isUsingIframe()): ?>
197  var url = '<?= /* @escapeNotVerified */ $block->getSwitchUrl() ?>' + scopeParams;
198  setLocation(url);
199  <?php else: ?>
200  jQuery('#preview_selected_store').val(scopeId);
201  jQuery('#preview_form').submit();
202 
203  jQuery('.store-switcher .dropdown-menu li a').each(function() {
204  var $this = jQuery(this);
205 
206  if ($this.data('role') === 'store-view-id' && $this.data('value') == scopeId) {
207  jQuery('#store-change-button').html($this.text());
208  }
209  });
210 
211  jQuery('#store-change-button').click();
212  <?php endif; ?>
213  }
214  }
215 
216  window.scopeSwitcherHandler = scopeSwitcherHandler;
217  window.switchScope = switchScope;
218 
219 });
220 </script>
221 <?php endif; ?>
if( $websites=$block->getWebsites())(__( 'Choose Store View:')) ?></label >< div class $showWebsite
Definition: store.phtml:20
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
$group
Definition: sections.phtml:16
if( $form)() ?>< script > require(['jquery' mage mage
Definition: save.phtml:15
__()
Definition: __.php:13
$block
Definition: block.php:8
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203
foreach($block->getWebsiteCollection() as $_website) foreach($block->getGroupCollection($_website) as $_group) foreach( $block->getStoreCollection( $_group) as $_store)($showWebsite==false) if($block->getRequest() ->getParam('website')==$_website->getId()) endif
Definition: switcher.phtml:21
if($block->getStoreId()==$_store->getId()) endforeach
Definition: switcher.phtml:28