Exemple #1
0
 /**
  * This method does not flush ORM. You'll need to manually call it.
  *
  * @param RZ\Roadiz\Core\Entities\Group $newGroup
  *
  * @throws \RuntimeException If newGroup param is null
  */
 public function diff(Group $newGroup)
 {
     if (null !== $newGroup) {
         if ("" != $newGroup->getName()) {
             $this->group->setName($newGroup->getName());
         }
         $existingRolesNames = $this->group->getRoles();
         foreach ($newGroup->getRolesEntities() as $newRole) {
             if (false === in_array($newRole->getName(), $existingRolesNames)) {
                 $role = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneByName($newRole->getName());
                 $this->group->addRole($role);
             }
         }
     } else {
         throw new \RuntimeException("New group is null", 1);
     }
 }
 /**
  * Build edit group form with name constraint.
  *
  * @param RZ\Roadiz\Core\Entities\Group $group
  *
  * @return \Symfony\Component\Form\Form
  */
 protected function buildEditForm(Group $group)
 {
     $defaults = ['name' => $group->getName()];
     $builder = $this->createFormBuilder($defaults)->add('groupId', 'hidden', ['data' => $group->getId(), 'constraints' => [new NotBlank()]])->add('name', 'text', ['label' => 'group.name', 'data' => $group->getName(), 'constraints' => [new NotBlank()]]);
     return $builder->getForm();
 }