Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
20 
24 class Edit extends Action implements HttpGetActionInterface
25 {
29  const ADMIN_RESOURCE = 'Magento_InventoryApi::stock';
30 
34  private $stockRepository;
35 
40  public function __construct(
41  Context $context,
42  StockRepositoryInterface $stockRepository
43  ) {
44  parent::__construct($context);
45  $this->stockRepository = $stockRepository;
46  }
47 
51  public function execute(): ResultInterface
52  {
53  $stockId = (int)$this->getRequest()->getParam(StockInterface::STOCK_ID);
54  try {
55  $stock = $this->stockRepository->get($stockId);
56 
58  $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
59  $result->setActiveMenu('Magento_InventoryApi::stock')
60  ->addBreadcrumb(__('Edit Stock'), __('Edit Stock'));
61  $result->getConfig()
62  ->getTitle()
63  ->prepend(__('Edit Stock: %name', ['name' => $stock->getName()]));
64  } catch (NoSuchEntityException $e) {
66  $result = $this->resultRedirectFactory->create();
67  $this->messageManager->addErrorMessage(
68  __('Stock with id "%value" does not exist.', ['value' => $stockId])
69  );
70  $result->setPath('*/*');
71  }
72 
73  return $result;
74  }
75 }
__()
Definition: __.php:13
__construct(Context $context, StockRepositoryInterface $stockRepository)
Definition: Edit.php:40
$stockRepository
Definition: stock.php:19
$stock