messageFactory = $messageFactory; $this->urlBuilder = $urlBuilder; } /** * @inheritdoc */ public function createMessage(\Exception $exception, $type = MessageInterface::TYPE_ERROR) { if ($exception instanceof UrlAlreadyExistsException) { $generatedUrls = []; $urls = $exception->getUrls(); if ($urls && is_array($urls)) { foreach ($urls as $id => $url) { $adminEditUrl = $this->urlBuilder->getUrl( 'adminhtml/url_rewrite/edit', ['id' => $id] ); $generatedUrls[$adminEditUrl] = $url['request_path']; } } return $this->messageFactory->create($type) ->setIdentifier(self::URL_DUPLICATE_MESSAGE_MAP_ID) ->setText($exception->getMessage()) ->setData(['urls' => $generatedUrls]); } throw new RuntimeException( __('Exception instance doesn\'t match %1 type', UrlAlreadyExistsException::class) ); } }