Skip to content
Prev Previous commit
Next Next commit
i fixed a non working function in my helper
  • Loading branch information
francebenoit authored May 7, 2018
commit 8201642b22f674cb9f4f6803645a94b962905058
35 changes: 16 additions & 19 deletions form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,15 @@ the relationship between the removed ``Tag`` and ``Task`` object.

// 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 ;.

use Doctrine\Common\Collections\ArrayCollection;

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.


public function __construct(EntityManagerInterface $em)
{
$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.

{
$original_entities = new ArrayCollection();
Expand All @@ -767,22 +773,16 @@ the relationship between the removed ``Tag`` and ``Task`` object.
return $original_entities;
}

//this function removes totally the entity
public function removeEntity($original_entities, $current_entities)
{
foreach ($original_entities as $entity) {
if (false === $current_entities->contains($entity)) {
$em->remove($entity);
}
}
}

//this function removes only the relationship
public function removeRelation($original_entities, $main_entity,$current_entities, $function_name)
//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 [...]

public function removeRelation($original_entities, $main_entity,$current_entities, $function_name, $remove=false)
{
foreach ($original_entities as $entity) {
if (false === $current_entities->contains($entity)) {
$main_entity->$function_name($entity);

if($remove){
$this->em->remove($entity);
}
}
}
}
Expand Down Expand Up @@ -813,12 +813,9 @@ the relationship between the removed ``Tag`` and ``Task`` object.
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.

//depending on your needs
//either
$helper->removeRelation($original_entities,$event,$task->getTags(),'removeTag');
//or
$helper->removeEntity($original_entities,$event,$task->getTags());

//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.


$entityManager->persist($task);
$entityManager->flush();

Expand Down