-
-
Couldn't load subscription status.
- Fork 5.3k
Create helper to manage relationship removal #9709
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
Conversation
I use this in my project. This helper is reusable in any controller and reduce code. I hope you'll find this is a good way to do it and it can be shared with the community :)
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.
Hello @francebenoit! 👋 Thank you for your first ever contribution to the Symfony documentation. I have added some comments and requested changes. Other people will need to review your pull request to see if this is a good addition to the Symfony documentation.
form/form_collections.rst Outdated
| use Doctrine\ORM\EntityManagerInterface; | ||
| | ||
| class Helper | ||
| private $em; |
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.
The code indentation is not correct. The build is failing because of this. Can you correct this by using 4 spaces:
class Helper private $em; This also includes other indentation errors in your changes.
form/form_collections.rst Outdated
| You can optionnally reduce the code in your controller and make it reusable to handle other embedded form. | ||
| First create a helper | ||
| | ||
| // App\Helper; |
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.
You could remove the ;.
form/form_collections.rst Outdated
| return $original_entities; | ||
| } | ||
| | ||
| //this function removes only the relationship, removes the entity if $remove set to true |
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.
There is no space between // and t: // this function removes only [...]
form/form_collections.rst Outdated
| { | ||
| $this->em = $em; | ||
| } | ||
| public function backupOriginalEntities($entities) |
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.
There is a empty line missing between these functions.
form/form_collections.rst Outdated
| | ||
| if ($editForm->isValid()) { | ||
| | ||
| // remove the relationship between the tag and the Task |
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 comment could be on one line since the second comment line is not correctly styled.
form/form_collections.rst Outdated
| | ||
| // remove the relationship between the tag and the Task | ||
| //depending on your needs | ||
| $helper->removeRelation($original_entities,$event,$task->getTags(),'removeTag',true); // or let blank if you want to keep orphan |
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.
You can remove the comment on the end and place that to the comment above;
// Remove the relationship between the tag and the Task depending on your needs or let blank if you want to keep orphan
The spelling on this comment is incorrect.
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.
The build is failing for unexpected indentation:
/home/travis/build/symfony/symfony-docs/form/form_collections.rst:759: ERROR: Unexpected indentation. Could you fix it up @francebenoit?
i fix an indent error. I hope it was the last one !
| @ndench I fix one but iI guess there are more. I'll check the file again and resubmit |
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.
@ndench I fix one but iI guess there are more. I'll check the file again and resubmit
Thank you @francebenoit. The tests are passed.
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.
Awesome, thanks @francebenoit!
| thanks @ndench |
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.
I left some comments
| | ||
| | ||
| Optionnal helper to handle tags removals | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
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.
Please add a blank line after the headline
| .. _`JSFiddle`: http://jsfiddle.net/847Kf/4/ | ||
| .. _`symfony-collection`: https://github.com/ninsuo/symfony-collection | ||
| | ||
| |
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.
Please remove one blank line
| | ||
| | ||
| | ||
| Optionnal helper to handle tags removals |
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.
Typo in optional (only 1 n)
| | ||
| Optionnal helper to handle tags removals | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| You can optionnally reduce the code in your controller and make a reusable service to handle all your embedded form. |
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.
Same typo in optionNaly and only one L
| | ||
| // Create an ArrayCollection of the current objects in the database | ||
| foreach ($entities as $entity) { | ||
| $original_entities->add($entity); |
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.
Please use cameCase for variable names
| | ||
| First create a helper:: | ||
| | ||
| // src\Helper |
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.
src/Helper/Helper.php
but we should find a better name than „Helper“
| throw $this->createNotFoundException('No task found for id '.$id); | ||
| } | ||
| $original_entities = $helper->backupOriginalEntities($event->getOrganizationTypes()); |
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.
$helper and $event is not defined
I use this in my project. This helper is reusable in any controller and reduce code.
I hope you'll find this is a good way to do it and it can be shared with the community :)