Sidebar.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © 2015 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Block;
  9. use Magento\Store\Model\ScopeInterface;
  10. /**
  11. * Blog sidebar block
  12. */
  13. class Sidebar extends \Magento\Framework\View\Element\Text
  14. {
  15. /**
  16. * Render html output
  17. *
  18. * @return string
  19. */
  20. protected function _toHtml()
  21. {
  22. $this->setText('');
  23. $childNames = $this->getChildNames();
  24. usort($childNames, [$this, 'sortChilds']);
  25. $layout = $this->getLayout();
  26. foreach ($childNames as $child) {
  27. $this->addText($layout->renderElement($child, false));
  28. }
  29. return parent::_toHtml();
  30. }
  31. /**
  32. * Sort by sort order param
  33. * @param string $a
  34. * @param string $b
  35. * @return boolean
  36. */
  37. public function sortChilds($a, $b)
  38. {
  39. $layout = $this->getLayout();
  40. $blockA = $layout->getBlock($a);
  41. $blockB = $layout->getBlock($b);
  42. if ($blockA && $blockB) {
  43. $r = $blockA->getSortOrder() > $blockB->getSortOrder() ? 1 : - 1;
  44. return $r;
  45. }
  46. }
  47. }