Skip to content

Conversation

@francebenoit
Copy link

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 :)

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 :)
Copy link

@ghost ghost left a 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.

use Doctrine\ORM\EntityManagerInterface;

class Helper
private $em;
Copy link

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.

You can optionnally reduce the code in your controller and make it reusable to handle other embedded form.
First create a helper

// App\Helper;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove the ;.

return $original_entities;
}

//this function removes only the relationship, removes the entity if $remove set to true
Copy link

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 [...]

{
$this->em = $em;
}
public function backupOriginalEntities($entities)
Copy link

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.


if ($editForm->isValid()) {

// remove the relationship between the tag and the Task
Copy link

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.


// 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
Copy link

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.

Copy link
Contributor

@ndench ndench left a 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 !
@francebenoit
Copy link
Author

@ndench I fix one but iI guess there are more. I'll check the file again and resubmit

Copy link

@ghost ghost left a 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.

Copy link
Contributor

@ndench ndench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks @francebenoit!

@francebenoit
Copy link
Author

thanks @ndench

Copy link
Contributor

@OskarStark OskarStark left a 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Contributor

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


Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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

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
Copy link
Contributor

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());
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants