resultPageFactory = $resultPageFactory; parent::__construct($context, $coreRegistry); } /** * Edit action * * @return ResultInterface */ public function execute() { // 1. Get ID and create model $id = $this->getRequest()->getParam('location_id'); $model = $this->_objectManager->create(Location::class); // 2. Initial checking if ($id) { $model->load($id); if (!$model->getId()) { $this->messageManager->addErrorMessage(__('This Location no longer exists.')); /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } $this->_coreRegistry->register('olegnax_googlemap_location', $model); // 3. Build edit form /** @var Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $this->initPage($resultPage)->addBreadcrumb( $id ? __('Edit Location') : __('New Location'), $id ? __('Edit Location') : __('New Location') ); $resultPage->getConfig()->getTitle()->prepend(__('Locations')); $resultPage->getConfig()->getTitle()->prepend( $model->getId() ? __( 'Edit Location %1', $model->getId() ) : __('New Location') ); return $resultPage; } }