From 6ebf2c7e42648733b6d96e1d81449ef1919fc655 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Mon, 7 Jul 2014 22:44:39 +0200 Subject: [PATCH] Fixed "with the close or save and close button you get an exception" --- .../Controller/Admin/FileController.php | 19 ++++++++++++------- core/lib/Thelia/Files/FileModelInterface.php | 2 +- core/lib/Thelia/Model/BrandDocument.php | 4 ++-- core/lib/Thelia/Model/BrandImage.php | 4 ++-- core/lib/Thelia/Model/CategoryDocument.php | 4 ++-- core/lib/Thelia/Model/CategoryImage.php | 4 ++-- core/lib/Thelia/Model/ContentDocument.php | 4 ++-- core/lib/Thelia/Model/ContentImage.php | 4 ++-- core/lib/Thelia/Model/FolderDocument.php | 4 ++-- core/lib/Thelia/Model/FolderImage.php | 4 ++-- core/lib/Thelia/Model/ProductDocument.php | 4 ++-- core/lib/Thelia/Model/ProductImage.php | 4 ++-- .../backOffice/default/document-edit.html | 6 +++--- templates/backOffice/default/image-edit.html | 6 +++--- 14 files changed, 39 insertions(+), 34 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/FileController.php b/core/lib/Thelia/Controller/Admin/FileController.php index b4f373413..c4f9401aa 100644 --- a/core/lib/Thelia/Controller/Admin/FileController.php +++ b/core/lib/Thelia/Controller/Admin/FileController.php @@ -269,10 +269,10 @@ class FileController extends BaseAdminController $fileManager = $this->getFileManager(); $imageModel = $fileManager->getModelInstance('image', $parentType); - $redirectUrl = $imageModel->getRedirectionUrl($imageId); - $image = $imageModel->getQueryInstance()->findPk($imageId); + $redirectUrl = $image->getRedirectionUrl(); + return $this->render('image-edit', array( 'imageId' => $imageId, 'imageType' => $parentType, @@ -306,7 +306,7 @@ class FileController extends BaseAdminController $document = $documentModel->getQueryInstance()->findPk($documentId); - $redirectUrl = $documentModel->getRedirectionUrl($documentId); + $redirectUrl = $document->getRedirectionUrl(); return $this->render('document-edit', array( 'documentId' => $documentId, @@ -394,7 +394,13 @@ class FileController extends BaseAdminController ); if ($this->getRequest()->get('save_mode') == 'close') { - $this->redirect(URL::getInstance()->absoluteUrl($fileModelInstance->getRedirectionUrl($fileId))); + + if ($objectType == 'document') + $tab = 'documents'; + else + $tab = 'images'; + + $this->redirect(URL::getInstance()->absoluteUrl($file->getRedirectionUrl(), ['current_tab' => $tab])); } else { $this->redirectSuccess($fileUpdateForm); } @@ -417,7 +423,7 @@ class FileController extends BaseAdminController ->setGeneralError($message); } - return $fileModelInstance; + return $file; } /** @@ -454,7 +460,6 @@ class FileController extends BaseAdminController */ public function updateDocumentAction($documentId, $parentType) { - if (null !== $response = $this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE)) { return $response; } @@ -464,7 +469,7 @@ class FileController extends BaseAdminController return $this->render('document-edit', array( 'documentId' => $documentId, 'documentType' => $parentType, - 'redirectUrl' => $documentInstance->getRedirectionUrl($documentId), + 'redirectUrl' => $documentInstance->getRedirectionUrl(), 'formId' => $documentInstance->getUpdateFormId() )); } diff --git a/core/lib/Thelia/Files/FileModelInterface.php b/core/lib/Thelia/Files/FileModelInterface.php index 589e071ec..8165e3f36 100644 --- a/core/lib/Thelia/Files/FileModelInterface.php +++ b/core/lib/Thelia/Files/FileModelInterface.php @@ -75,7 +75,7 @@ interface FileModelInterface * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId); + public function getRedirectionUrl(); /** * Get the Query instance for this object diff --git a/core/lib/Thelia/Model/BrandDocument.php b/core/lib/Thelia/Model/BrandDocument.php index 432ad69f3..b47ffe491 100644 --- a/core/lib/Thelia/Model/BrandDocument.php +++ b/core/lib/Thelia/Model/BrandDocument.php @@ -113,9 +113,9 @@ class BrandDocument extends BaseBrandDocument implements BreadcrumbInterface, Fi * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/brand/update/' . $objectId . '?current_tab=document'; + return '/admin/brand/update/' . $this->getBrandId(); } /** diff --git a/core/lib/Thelia/Model/BrandImage.php b/core/lib/Thelia/Model/BrandImage.php index 9cd115a06..212847218 100644 --- a/core/lib/Thelia/Model/BrandImage.php +++ b/core/lib/Thelia/Model/BrandImage.php @@ -113,9 +113,9 @@ class BrandImage extends BaseBrandImage implements FileModelInterface, Breadcrum * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/brand/update/' . $objectId . '?current_tab=image'; + return '/admin/brand/update/' . $this->getBrandId(); } /** diff --git a/core/lib/Thelia/Model/CategoryDocument.php b/core/lib/Thelia/Model/CategoryDocument.php index 3e13863bb..db3525341 100644 --- a/core/lib/Thelia/Model/CategoryDocument.php +++ b/core/lib/Thelia/Model/CategoryDocument.php @@ -123,9 +123,9 @@ class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterfa * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/categories/update?category_id=' . $objectId . '?current_tab=document'; + return '/admin/categories/update?category_id=' . $this->getCategoryId(); } /** diff --git a/core/lib/Thelia/Model/CategoryImage.php b/core/lib/Thelia/Model/CategoryImage.php index 75c66f967..d6c6d9899 100644 --- a/core/lib/Thelia/Model/CategoryImage.php +++ b/core/lib/Thelia/Model/CategoryImage.php @@ -123,9 +123,9 @@ class CategoryImage extends BaseCategoryImage implements BreadcrumbInterface, Fi * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/categories/update?category_id=' . $objectId . '?current_tab=image'; + return '/admin/categories/update?category_id=' . $this->getCategoryId(); } /** diff --git a/core/lib/Thelia/Model/ContentDocument.php b/core/lib/Thelia/Model/ContentDocument.php index c2fb09ada..abde4f36a 100644 --- a/core/lib/Thelia/Model/ContentDocument.php +++ b/core/lib/Thelia/Model/ContentDocument.php @@ -123,9 +123,9 @@ class ContentDocument extends BaseContentDocument implements BreadcrumbInterface * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/content/update/' . $objectId . '?current_tab=document'; + return '/admin/content/update/' . $this->getContentId(); } /** diff --git a/core/lib/Thelia/Model/ContentImage.php b/core/lib/Thelia/Model/ContentImage.php index 7172e8b51..cefcca112 100644 --- a/core/lib/Thelia/Model/ContentImage.php +++ b/core/lib/Thelia/Model/ContentImage.php @@ -121,9 +121,9 @@ class ContentImage extends BaseContentImage implements BreadcrumbInterface, File * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/content/update/' . $objectId . '?current_tab=image'; + return '/admin/content/update/' . $this->getContentId(); } /** diff --git a/core/lib/Thelia/Model/FolderDocument.php b/core/lib/Thelia/Model/FolderDocument.php index caae33b31..14e660dd9 100644 --- a/core/lib/Thelia/Model/FolderDocument.php +++ b/core/lib/Thelia/Model/FolderDocument.php @@ -120,9 +120,9 @@ class FolderDocument extends BaseFolderDocument implements BreadcrumbInterface, * @param int $objectId the ID of the parent object * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/folder/update/' . $objectId . '?current_tab=image'; + return '/admin/folder/update/' . $this->getFolderId(); } /** diff --git a/core/lib/Thelia/Model/FolderImage.php b/core/lib/Thelia/Model/FolderImage.php index 5082d089b..31b9024c6 100644 --- a/core/lib/Thelia/Model/FolderImage.php +++ b/core/lib/Thelia/Model/FolderImage.php @@ -120,9 +120,9 @@ class FolderImage extends BaseFolderImage implements BreadcrumbInterface, FileMo * @param int $objectId the ID of the parent object * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/folder/update/' . $objectId . '?current_tab=image'; + return '/admin/folder/update/' . $this->getFolderId(); } /** diff --git a/core/lib/Thelia/Model/ProductDocument.php b/core/lib/Thelia/Model/ProductDocument.php index 1706e2cd4..04f867342 100644 --- a/core/lib/Thelia/Model/ProductDocument.php +++ b/core/lib/Thelia/Model/ProductDocument.php @@ -123,9 +123,9 @@ class ProductDocument extends BaseProductDocument implements BreadcrumbInterface * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/products/update?product_id=' . $objectId . '?current_tab=document'; + return '/admin/products/update?product_id=' . $this->getProductId(); } /** diff --git a/core/lib/Thelia/Model/ProductImage.php b/core/lib/Thelia/Model/ProductImage.php index d6a753cea..e33683917 100644 --- a/core/lib/Thelia/Model/ProductImage.php +++ b/core/lib/Thelia/Model/ProductImage.php @@ -122,9 +122,9 @@ class ProductImage extends BaseProductImage implements BreadcrumbInterface, File * * @return string the URL to redirect to after update from the back-office */ - public function getRedirectionUrl($objectId) + public function getRedirectionUrl() { - return '/admin/products/update?product_id=' . $objectId . '?current_tab=image'; + return '/admin/products/update?product_id=' . $this->getProductId(); } /** diff --git a/templates/backOffice/default/document-edit.html b/templates/backOffice/default/document-edit.html index 09e06a6b8..7be7ed9d4 100644 --- a/templates/backOffice/default/document-edit.html +++ b/templates/backOffice/default/document-edit.html @@ -35,7 +35,7 @@ hide_submit_buttons = false page_url = "{url path="/admin/document/type/{$documentType}/{$ID}/update"}" - close_url = "{url path="{$redirectUrl}" noamp=1}" + close_url = "{url path="{$redirectUrl}" current_tab="documents" noamp=1}" } {form_hidden_fields form=$form} @@ -75,7 +75,7 @@ hide_flags = true page_url = "{url path="/admin/document/type/{$documentType}/{$ID}/update"}" - close_url = "{url path="{$redirectUrl}"}" + close_url = "{url path="{$redirectUrl}" current_tab="documents"}" } {/form} @@ -95,7 +95,7 @@
diff --git a/templates/backOffice/default/image-edit.html b/templates/backOffice/default/image-edit.html index 697b08501..0d0ea9096 100644 --- a/templates/backOffice/default/image-edit.html +++ b/templates/backOffice/default/image-edit.html @@ -35,7 +35,7 @@ hide_submit_buttons = false page_url = "{url path="/admin/image/type/{$imageType}/{$ID}/update"}" - close_url = "{url path="{$redirectUrl}" noamp=1}" + close_url = "{url path="{$redirectUrl}" current_tab="images" noamp=1}" } {form_hidden_fields form=$form} @@ -78,7 +78,7 @@ hide_flags = true page_url = "{url path="/admin/image/type/{$imageType}/{$ID}/update"}" - close_url = "{url path="{$redirectUrl}"}" + close_url = "{url path="{$redirectUrl}" current_tab="images"}" } {/form} @@ -98,7 +98,7 @@