Add.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Model\Menu\Builder\Command;
  7. /**
  8. * Builder command to add menu items
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Add extends \Magento\Backend\Model\Menu\Builder\AbstractCommand
  13. {
  14. /**
  15. * List of params that command requires for execution
  16. *
  17. * @var string[]
  18. */
  19. protected $_requiredParams = ["id", "title", "module", "resource"];
  20. /**
  21. * Add command as last in the list of callbacks
  22. *
  23. * @param \Magento\Backend\Model\Menu\Builder\AbstractCommand $command
  24. * @return $this
  25. * @throws \InvalidArgumentException
  26. */
  27. public function chain(\Magento\Backend\Model\Menu\Builder\AbstractCommand $command)
  28. {
  29. if ($command instanceof \Magento\Backend\Model\Menu\Builder\Command\Add) {
  30. throw new \InvalidArgumentException("Two 'add' commands cannot have equal id (" . $command->getId() . ")");
  31. }
  32. return parent::chain($command);
  33. }
  34. /**
  35. * Add missing data to item
  36. *
  37. * @param array $itemParams
  38. * @return array
  39. */
  40. protected function _execute(array $itemParams)
  41. {
  42. foreach ($this->_data as $key => $value) {
  43. $itemParams[$key] = isset($itemParams[$key]) ? $itemParams[$key] : $value;
  44. }
  45. return $itemParams;
  46. }
  47. }