mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-26 17:43:54 +00:00
fix deprecations: use fqcn for submit in controllers
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\UserType;
|
||||
@@ -11,13 +12,14 @@ use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Form\Type\ComposedGroupCenterType;
|
||||
use Chill\MainBundle\Form\UserPasswordType;
|
||||
|
||||
|
||||
/**
|
||||
* User controller.
|
||||
*
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
|
||||
const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter';
|
||||
|
||||
/**
|
||||
@@ -46,10 +48,10 @@ class UserController extends Controller
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
|
||||
$user->setPassword($this->get('security.password_encoder')
|
||||
->encodePassword($user, $form['plainPassword']['password']->getData()));
|
||||
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
@@ -77,7 +79,7 @@ class UserController extends Controller
|
||||
'is_creation' => true
|
||||
));
|
||||
|
||||
$form->add('submit', 'submit', array('label' => 'Create'));
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Create'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
@@ -136,15 +138,15 @@ class UserController extends Controller
|
||||
'entity' => $user,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user)->createView(),
|
||||
'delete_groupcenter_form' => array_map(
|
||||
'delete_groupcenter_form' => array_map(
|
||||
function(\Symfony\Component\Form\Form $form) {
|
||||
return $form->createView();
|
||||
|
||||
|
||||
},
|
||||
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user), true))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Displays a form to edit the user password.
|
||||
*
|
||||
@@ -166,25 +168,25 @@ class UserController extends Controller
|
||||
'edit_form' => $editForm->createView()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param User $user
|
||||
* @return \Symfony\Component\Form\Form
|
||||
*/
|
||||
private function createEditPasswordForm(User $user)
|
||||
{
|
||||
return $this->createForm(new UserPasswordType(), $user, array(
|
||||
'action' =>
|
||||
'action' =>
|
||||
$this->generateUrl('admin_user_update_password', array('id' => $user->getId())),
|
||||
'method' => 'PUT'
|
||||
))
|
||||
->add('submit', 'submit', array('label' => 'Change password'))
|
||||
->add('submit', SubmitType::class, array('label' => 'Change password'))
|
||||
;
|
||||
}
|
||||
|
||||
public function deleteLinkGroupCenterAction($uid, $gcid)
|
||||
|
||||
public function deleteLinkGroupCenterAction($uid, $gcid)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
@@ -193,32 +195,32 @@ class UserController extends Controller
|
||||
if (!$user) {
|
||||
throw $this->createNotFoundException('Unable to find User entity.');
|
||||
}
|
||||
|
||||
|
||||
$groupCenter = $em->getRepository('ChillMainBundle:GroupCenter')
|
||||
->find($gcid);
|
||||
|
||||
|
||||
if (!$groupCenter) {
|
||||
throw $this->createNotFoundException('Unable to find groupCenter entity');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$user->removeGroupCenter($groupCenter);
|
||||
} catch (\RuntimeException $ex) {
|
||||
$this->addFlash('error', $this->get('translator')->trans($ex-getMessage()));
|
||||
|
||||
|
||||
return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $uid)));
|
||||
}
|
||||
|
||||
|
||||
$em->flush();
|
||||
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans('The permissions where removed.'));
|
||||
|
||||
|
||||
return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $uid)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function addLinkGroupCenterAction(Request $request, $uid)
|
||||
|
||||
public function addLinkGroupCenterAction(Request $request, $uid)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
@@ -227,21 +229,21 @@ class UserController extends Controller
|
||||
if (!$user) {
|
||||
throw $this->createNotFoundException('Unable to find User entity.');
|
||||
}
|
||||
|
||||
|
||||
$form = $this->createAddLinkGroupCenterForm($user);
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
if ($form->isValid()) {
|
||||
$groupCenter = $this->getPersistedGroupCenter(
|
||||
$form[self::FORM_GROUP_CENTER_COMPOSED]->getData());
|
||||
$user->addGroupCenter($groupCenter);
|
||||
|
||||
|
||||
if ($this->get('validator')->validate($user)->count() === 0) {
|
||||
$em->flush();
|
||||
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans('The '
|
||||
. 'permissions have been successfully added to the user'));
|
||||
|
||||
|
||||
return $this->redirect($this->generateUrl('admin_user_edit',
|
||||
array('id' => $uid)));
|
||||
} else {
|
||||
@@ -249,35 +251,35 @@ class UserController extends Controller
|
||||
$this->addFlash('error', $error->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->render('ChillMainBundle:User:edit.html.twig', array(
|
||||
'entity' => $user,
|
||||
'edit_form' => $this->createEditForm($user)->createView(),
|
||||
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user)->createView(),
|
||||
'delete_groupcenter_form' => array_map(
|
||||
'delete_groupcenter_form' => array_map(
|
||||
function(\Symfony\Component\Form\Form $form) {
|
||||
return $form->createView();
|
||||
|
||||
|
||||
},
|
||||
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user), true))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
private function getPersistedGroupCenter(GroupCenter $groupCenter)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
|
||||
$groupCenterManaged = $em->getRepository('ChillMainBundle:GroupCenter')
|
||||
->findOneBy(array(
|
||||
'center' => $groupCenter->getCenter(),
|
||||
'permissionsGroup' => $groupCenter->getPermissionsGroup()
|
||||
));
|
||||
|
||||
|
||||
if (!$groupCenterManaged) {
|
||||
$em->persist($groupCenter);
|
||||
return $groupCenter;
|
||||
}
|
||||
|
||||
|
||||
return $groupCenterManaged;
|
||||
}
|
||||
|
||||
@@ -295,11 +297,11 @@ class UserController extends Controller
|
||||
'method' => 'PUT',
|
||||
));
|
||||
|
||||
$form->add('submit', 'submit', array('label' => 'Update'));
|
||||
$form->add('submit', SubmitType::class, array('label' => 'Update'));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edits an existing User entity.
|
||||
*
|
||||
@@ -327,15 +329,15 @@ class UserController extends Controller
|
||||
'entity' => $user,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user)->createView(),
|
||||
'delete_groupcenter_form' => array_map(
|
||||
'delete_groupcenter_form' => array_map(
|
||||
function(\Symfony\Component\Form\Form $form) {
|
||||
return $form->createView();
|
||||
|
||||
|
||||
},
|
||||
iterator_to_array($this->getDeleteLinkGroupCenterByUser($user), true))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edits the user password
|
||||
*
|
||||
@@ -355,20 +357,20 @@ class UserController extends Controller
|
||||
|
||||
if ($editForm->isValid()) {
|
||||
$password = $editForm->getData()->getPassword();
|
||||
|
||||
|
||||
// logging for debug !! WARNING print the new password !!
|
||||
$this->get('logger')->debug('update password for an user',
|
||||
array('method' => __METHOD__, 'password' => $password,
|
||||
$this->get('logger')->debug('update password for an user',
|
||||
array('method' => __METHOD__, 'password' => $password,
|
||||
'user' => $user->getUsername()));
|
||||
// logging for prod
|
||||
$this->get('logger')->info('update password for an user',
|
||||
$this->get('logger')->info('update password for an user',
|
||||
array('method' => __METHOD__, 'user' => $user->getUsername()));
|
||||
|
||||
|
||||
$user->setPassword($this->get('security.password_encoder')
|
||||
->encodePassword($user, $password));
|
||||
|
||||
|
||||
$em->flush();
|
||||
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans('Password successfully updated!'));
|
||||
|
||||
return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $id)));
|
||||
@@ -380,7 +382,7 @@ class UserController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a form to delete a link to a GroupCenter
|
||||
*
|
||||
@@ -391,34 +393,34 @@ class UserController extends Controller
|
||||
private function createDeleteLinkGroupCenterForm(User $user, GroupCenter $groupCenter)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('admin_user_delete_group_center',
|
||||
->setAction($this->generateUrl('admin_user_delete_group_center',
|
||||
array('uid' => $user->getId(), 'gcid' => $groupCenter->getId())))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', 'submit', array('label' => 'Delete'))
|
||||
->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create a form to add a link to a groupcenter
|
||||
*
|
||||
*
|
||||
* @param User $user
|
||||
* @return \Symfony\Component\Form\Form
|
||||
*/
|
||||
private function createAddLinkGroupCenterForm(User $user)
|
||||
{
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('admin_user_add_group_center',
|
||||
->setAction($this->generateUrl('admin_user_add_group_center',
|
||||
array('uid' => $user->getId())))
|
||||
->setMethod('POST')
|
||||
->add(self::FORM_GROUP_CENTER_COMPOSED, new ComposedGroupCenterType())
|
||||
->add('submit', 'submit', array('label' => 'Add a new groupCenter'))
|
||||
->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter'))
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
private function getDeleteLinkGroupCenterByUser(User $user)
|
||||
|
Reference in New Issue
Block a user