I have problem with creating new page from backend it shows me this message: Something went wrong while saving the page.
I can edit and save the page but I can't create the new page. any idea??
I have problem with creating new page from backend it shows me this message: Something went wrong while saving the page.
I can edit and save the page but I can't create the new page. any idea??
Yes I got the solution for that:
I have installed MageWorx SeoBase extension that extension adds two fields in the cms_page table: 1. meta_robots and 2. mageworx_hreflang_identifier
but that field does not show on the content > page and both fields are set as nullable = false;
that's why the page was not saving I just go the database, open the cms_page table and just select true in a null field and now its working.
The best idea to get the solution is try and catch which was introduced in PHP 5 then you only need to check exception message.
try{
//Your code logic
}
catch (\Exception $e) {
//First find the message and then echo $e message.
echo $e->getMessage(); die('errorMessage');
$this->messageManager->addException($e, __('Something went wrong while saving the page.'));
}
Magento\Cms\Controller\Adminhtml\Page\InlineEdit
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->jsonFactory->create();
$error = false;
$messages = [];
$postItems = $this->getRequest()->getParam('items', []);
if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
return $resultJson->setData([
'messages' => [__('Please correct the data sent.')],
'error' => true,
]);
}
foreach (array_keys($postItems) as $pageId) {
/** @var \Magento\Cms\Model\Page $page */
$page = $this->pageRepository->getById($pageId);
try {
/*Magento issue fix since it passes Invalid date for custom_theme_from*/
$dataset = $postItems[$pageId];
if(isset($dataset['custom_theme_from']) && $dataset['custom_theme_from']=="Invalid date"){
unset($dataset['custom_theme_from']);
}
if(isset($dataset['custom_theme_to']) && $dataset['custom_theme_to']=="Invalid date"){
unset($dataset['custom_theme_to']);
}
$postItems[$pageId] = $dataset;
$pageData = $this->filterPost($postItems[$pageId]);
$this->validatePost($pageData, $page, $error, $messages);
$extendedPageData = $page->getData();
$this->setCmsPageData($page, $extendedPageData, $pageData);
$this->pageRepository->save($page);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$messages[] = $this->getErrorWithPageId($page, $e->getMessage());
$error = true;
} catch (\RuntimeException $e) {
$messages[] = $this->getErrorWithPageId($page, $e->getMessage());
$error = true;
} catch (\Exception $e) {
$messages[] = $this->getErrorWithPageId(
$page,
__('Something went wrong while saving the page.')
);
$error = true;
}
}
return $resultJson->setData([
'messages' => $messages,
'error' => $error
]);
}