Skip to content
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

Merged
merged 9 commits into from
Aug 16, 2018

Conversation

sir-kain
Copy link
Contributor

@sir-kain sir-kain commented Aug 14, 2018

Subject

From the CRUDController:editAction() add an error message before rendering the html page if no field is defined on the configureFormFields() function

Changelog

### Added
- Added exception message if no field is defined on the  `configureFormFields()` function

@@ -300,6 +300,7 @@ public function deleteAction($id)
*
* @param int|string|null $id
*
* @throws \RuntimeException If no editable attribut is defined
Copy link
Member

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

@@ -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?'));
Copy link
Contributor

@kunicmarko20 kunicmarko20 Aug 14, 2018

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.

Copy link
Contributor

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?

@@ -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
Copy link
Member

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?

@@ -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?');
Copy link
Contributor

@greg0ire greg0ire Aug 14, 2018

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?'
);

@kunicmarko20
Copy link
Contributor

Please add a test for this case

@OskarStark
Copy link
Member

OskarStark commented Aug 16, 2018

Thanks for the test, but can you add one returning false , too?

@kunicmarko20
Copy link
Contributor

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

@sir-kain
Copy link
Contributor Author

@OskarStark done?

@sir-kain
Copy link
Contributor Author

@kunicmarko20 Yes, I thought about that.
But in another PR?

@OskarStark OskarStark merged commit b5613a1 into sonata-project:3.x Aug 16, 2018
@OskarStark
Copy link
Member

Thank you @sir-kaine, would be great if you could add another PR 👍🏻

@greg0ire greg0ire added the patch label Aug 16, 2018
@@ -330,6 +331,12 @@ public function editAction($id = null)
$this->admin->setSubject($existingObject);
$objectId = $this->admin->getNormalizedIdentifier($existingObject);

if (!$this->admin->getFormTabs()) {
Copy link

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.

Copy link
Contributor

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

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants