-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CRUD:Edit] Add exception message #5190
Conversation
src/Controller/CRUDController.php
Outdated
@@ -300,6 +300,7 @@ public function deleteAction($id) | |||
* | |||
* @param int|string|null $id | |||
* | |||
* @throws \RuntimeException If no editable attribut is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attributE, but IMO field
would better
src/Controller/CRUDController.php
Outdated
@@ -330,6 +331,10 @@ public function editAction($id = null) | |||
$this->admin->setSubject($existingObject); | |||
$objectId = $this->admin->getNormalizedIdentifier($existingObject); | |||
|
|||
if (!$this->admin->getFormTabs()) { | |||
throw new \RuntimeException(sprintf('No editable field defined. Did you forget to implement the "configureFormFields" method?')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is too long, could you please break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why are you using sprintf
here?
src/Controller/CRUDController.php
Outdated
@@ -300,6 +300,7 @@ public function deleteAction($id) | |||
* | |||
* @param int|string|null $id | |||
* | |||
* @throws \RuntimeException If no editable field is defined | |||
* @throws NotFoundHttpException If the object does not exist | |||
* @throws AccessDeniedException If access is not granted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please move the \RuntimeException
below the AccessDeniedException
?
…ccessDeniedException'
src/Controller/CRUDController.php
Outdated
@@ -330,6 +331,11 @@ public function editAction($id = null) | |||
$this->admin->setSubject($existingObject); | |||
$objectId = $this->admin->getNormalizedIdentifier($existingObject); | |||
|
|||
if (!$this->admin->getFormTabs()) { | |||
throw new \RuntimeException('No editable field defined. | |||
Did you forget to implement the "configureFormFields" method?'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<?php
throw new \RuntimeException(
'No editable field defined. Did you forget to implement the "configureFormFields" method?'
);
Please add a test for this case |
Thanks for the test, but can you add one returning false , too? |
Hey, @sir-kain this is a good solution, could you maybe apply it to create and show actions also? so we have consistency between actions. Thank you |
@OskarStark done? |
@kunicmarko20 Yes, I thought about that. |
Thank you @sir-kaine, would be great if you could add another PR 👍🏻 |
@@ -330,6 +331,12 @@ public function editAction($id = null) | |||
$this->admin->setSubject($existingObject); | |||
$objectId = $this->admin->getNormalizedIdentifier($existingObject); | |||
|
|||
if (!$this->admin->getFormTabs()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is BC break cause at this point form can be not initialized yet, but moving call:
$form = $this->admin->getForm();
Before this if
fixes that exception.
ps. mine admin controller don't overwrite any method of CRUDController
just adds new like in docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was fixed in #5195
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, just noticed fix: #5195
Subject
From the
CRUDController:editAction()
add an error message before rendering the html page if no field is defined on theconfigureFormFields()
functionChangelog