I need to get data grid on the controller but it does not allow to enter parameters in the function. How you recover that information?
services:
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, AppBundle:CRUDCategory, ~]
tags:
- { name: sonata.admin, manager_type: orm, group: "General", label: Categories }
This is the controller
<?php
namespace AppBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as SonataController;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery as ProxyQueryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class CRUDCategoryController extends SonataController {
/**
* #param ProxyQueryInterface $selectedModelQuery
* #param Request $request
*
* #return RedirectResponse
*/
public function batchActionInactive(ProxyQueryInterface $selectedModelQuery, Request $request) {
$em = $this->getDoctrine()->getManager();
$category = $em->getRepository('AppBundle:Category')->find($request->getId());
$category->setState('INACTIVE');
$em->flush();
return new RedirectResponse(
$this->admin->generateUrl('list', $this->admin->getFilterParameters())
);
}
}
And this is the function getBatchActions
public function getBatchActions() {
$actions = parent::getBatchActions();
unset($actions['delete']);
$actions['inactive'] = array(
'label' => 'Disable category',
'ask_confirmation' => false
);
return $actions;
}
The error is
Catchable Fatal Error: Argument 2 passed to
AppBundle\Controller\CRUDCategoryController::batchActionInactive()
must be an instance of AppBundle\Controller\Request, none given
It is much easier, do it this way instead of getting the categories by your own:
/**
* #param ProxyQueryInterface $selectedModelQuery
*
* #return RedirectResponse
*/
public function batchActionInactive(ProxyQueryInterface $selectedModelQuery)
{
$selectedCategories = $selectedModelQuery->execute();
try {
/** #var Category $category */
foreach ($selectedCategories as $category) {
$category->setState('INACTIVE');
$this->admin->update($category);
}
} catch (\Exception $e) {
$this->addFlash(
'sonata_flash_error',
'Could not mark Categories "INACTIVE"'
);
$this->get('logger')->error($e->getMessage());
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
$this->addFlash(
'sonata_flash_success',
'Categories were marked as "INACTIVE"'
);
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
This has nothing to do with Sonata and everything to do with Symfony : you forgot the use statement for Request. The AppBundle\Controller\Request should have made you realize that ;)
EDIT: second error : action methods should end with **Action*
I've already solved.
public function batchActionInactive(ProxyQueryInterface $selectedModelQuery) {
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$ids = $request->request->get('idx');
foreach ($ids as $id) {
$category = $em->getRepository('AppBundle:Category')->find($id);
$category->setState('INACTIVE');
$em->flush();
}
return new RedirectResponse(
$this->admin->generateUrl('list', $this->admin->getFilterParameters())
);
}
Related
For my project, I need to redirect the user after registration. In order to achieve that, I created an EventListener as described below :
My Event Listener :
namespace UserBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class RegistrationConfirmListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {#inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm'
);
}
public function onRegistrationConfirm(GetResponseUserEvent $event)
{
$url = $this->router->generate('standard_user_registration_success');
$event->setResponse(new RedirectResponse($url));
}
}
I registered it as a service in my service.yml :
services:
rs_user.registration_complet:
class: UserBundle\EventListener\RegistrationConfirmListener
arguments: [#router]
tags:
- { name: kernel.event_subscriber }
And I need to use it in my RegistrationController but I don't understand how to trigger it.
Here in my registerAction :
public function registerAction(Request $request)
{
$em = $this->get('doctrine.orm.entity_manager');
//Form creation based on my user entity
$user = new StandardUser();
$form = $this->createForm(RegistrationStandardUserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user ->setEnabled(true);
$em ->persist($user);
$em ->flush();
if ($user){
$dispatcher = $this->get('event_dispatcher');
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRM);
}
}
return $this->render('UserBundle:Registration:register.html.twig', array(
'form' => $form->createView()
));
}
I don't understand the Symfony2 documentation about the subject neither what I need to pass to the ->dispatch() function to trigger my event.
[EDIT]
I get this error when I register my user :
Type error: Argument 1 passed to
UserBundle\EventListener\RegistrationConfirmListener::onRegistrationConfirm()
must be an instance of UserBundle\EventListener\GetResponseUserEvent,
instance of Symfony\Component\EventDispatcher\Event given
500 Internal Server Error - FatalThrowableError
Your listener declares that it is subscribed to FOSUserEvents::REGISTRATION_CONFIRM but you are dispatching FOSUserEvents::REGISTRATION_COMPLETED. To trigger it you need to dispatch a FOSUserEvents::REGISTRATION_CONFIRM event
edit to match your edit, you need to pass the event in your services tags:
- { name: 'kernel.event_subscriber', event: 'fos_user.registration.confirm'}
Let me just start by saying "I know this question gets asked a lot." believe me when i say nothing has worked for me.
I have created a controller called PostController. This is a controller for my blog. When I navigate to my blog i get the following error Class App\Http\Controllers\PostController does not exist even though it does exist. The controller is called PostController.php. Here is what the route looks like Route::get('blog','PostController#index');. I have read that running some composer commands will help but none of them have helped me. composer dumpautoload as well as composer update. Am i missing some step here? Anyone run into a similar problem? Please let me know if additional information is needed.
EDIT
Here are the namespaces at the top.
use App\Http\Controllers;
use App\Posts;
use App\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\PostFormRequest;
use Illuminate\Http\Request;
Here is the whole Controller.
<?php
use App\Http\Controllers;
use App\Posts;
use App\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\PostFormRequest;
use Illuminate\Http\Request;
class PostController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
//fetch 5 posts from database which are active and latest
$posts = Posts::where('active',1)->orderBy('created_at','desc')->paginate(5);
//page heading
$title = 'Latest Posts';
//return home.blade.php template from resources/views folder
return view('blog/home')->withPosts($posts)->withTitle($title);
}
/**
* Show the form for creating a new resource.
*
* #return Response
*/
public function create(Request $request)
{
// if user can post i.e. user is admin or author
if($request->user()->can_post())
{
return view('blog.create');
}
else
{
return redirect('blog');
}
}
/**
* Store a newly created resource in storage.
*
* #return Response
*/
public function store(PostFormRequest $request)
{
$post = new Posts();
$post->title = $request->get('title');
$post->body = $request->get('body');
$post->slug = str_slug($post->title);
$post->author_id = $request->user()->id;
if($request->has('save'))
{
$post->active = 0;
$message = 'Post saved successfully';
}
else
{
$post->active = 1;
$message = 'Post published successfully';
}
$post->save();
return redirect('edit/'.$post->slug)->withMessage($message);
}
/**
* Display the specified resource.
*
* #param int $id
* #return Response
*/
public function show($slug)
{
$post = Posts::where('slug',$slug)->first();
if(!$post)
{
return redirect('/')->withErrors('requested page not found');
}
$comments = $post->comments;
return view('posts.show')->withPost($post)->withComments($comments);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return Response
*/
public function edit(Request $request,$slug)
{
$post = Posts::where('slug',$slug)->first();
if($post && ($request->user()->id == $post->author_id || $request->user()->is_admin())){
return view('posts.edit')->with('post',$post);
}
return redirect('blog')->withErrors('you have not sufficient permissions');
}
/**
* Update the specified resource in storage.
*
* #param int $id
* #return Response
*/
public function update(Request $request)
{
//
$post_id = $request->input('post_id');
$post = Posts::find($post_id);
if($post && ($post->author_id == $request->user()->id || $request->user()->is_admin()))
{
$title = $request->input('title');
$slug = str_slug($title);
$duplicate = Posts::where('slug',$slug)->first();
if($duplicate)
{
if($duplicate->id != $post_id)
{
return redirect('edit/'.$post->slug)->withErrors('Title already exists.')->withInput();
}
else
{
$post->slug = $slug;
}
}
$post->title = $title;
$post->body = $request->input('body');
if($request->has('save'))
{
$post->active = 0;
$message = 'Post saved successfully';
$landing = 'edit/'.$post->slug;
}
else {
$post->active = 1;
$message = 'Post updated successfully';
$landing = $post->slug;
}
$post->save();
return redirect($landing)->withMessage($message);
}
else
{
return redirect('blog')->withErrors('you have not sufficient permissions');
}
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return Response
*/
public function destroy(Request $request, $id)
{
//
$post = Posts::find($id);
if($post && ($post->author_id == $request->user()->id || $request->user()->is_admin()))
{
$post->delete();
$data['message'] = 'Post deleted Successfully';
}
else
{
$data['errors'] = 'Invalid Operation. You have not sufficient permissions';
}
return redirect('blog')->with($data);
}
}
Thanks.
Open App\Provider\RouteServiceProvider.php
and add
this line
protected $namespace = 'App\Http\Controllers';
below this
public const HOME = '/home';
and your error will vanish.
If composer dumpautoload is not helping then check if you have proper namespace declaration in PostController.php and double check for typos in class name/route declaration.
If this fails check composer.json for autoload configuration, it should have something like this:
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
As a side note you could use something like this:
Route::get('blog',PostController::class . '#index');
or
Route::get('blog',\App\Http\Controllers\PostController::class . '#index');
With this any decent IDE should give some kind of a warning if it can't find the file/there's a typo
Edit:
Your file should have a line like this
namespace App\Http\Controllers;
At the beggining of the file, right after <?php or <?php declare(strict_types = 1); if you're using php7 strict mode
Open App\Providers\RouteServiceProvider.php and uncomment or add the row:
protected $namespace = 'App\\Http\\Controllers';
if you use laravel 8.* then Open App->Providers>RouteServiceProvider.php and uncomment this line:
protected $namespace = 'App\Http\Controllers';
This happened in my upgrade from Laravel 7.x to 8.x. My fix was to change my routing from:
Route::resource('posts', 'PostController');
to:
Route::resource('posts', \App\Http\Controllers\PostController::class);
or if you import the PostController class:
Route::resource('posts', PostController::class);
The reason for this change is explained in the upgrade from Laravel 7.x to 8.x guide:
https://laravel.com/docs/8.x/upgrade#routing
It explains that it 8.x provides support to allow route declarations to use standard PHP callable syntax. The alternative solution is what others have mentioned, and add protected $namespace = 'App\Http\Controllers'; to RouteServiceProvider.
Simply, You would have to add class into the routes\web.php file as given below:
use App\Http\Controllers\PostController;
Symfony 2 ERROR: Cannot validate values of type "string" automatically. Please provide a constraint.
I do not understand what constraint and where i have to provide?
I am following example from book "Extending Symfony 2", chapter 4. I try to make custom annotation "ValidateUser" and use it on the Entity User property $phone. I also have "ValidUserListenerCustom" registered as a service, which redirects response of controller action join4Action. This action is annotated with said custom annotation "#ValidateUser("join_event")". This action should add User to the Event only if User has mobile number in his profile.
C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Entity\User.php
/**
* #ORM\Column(type="string", length=255, name="phone")
* #Assert\NotBlank(groups={"join_event"})
*/
protected $phone;
C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Security\ValidUserListenerCustom.php
<?php
namespace Yoda\UserBundle\Security;
use Doctrine\Common\Annotations\Reader;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
class ValidUserListenerCustom
{
private $reader;
private $annotation_name = 'Yoda\UserBundle\Security\Annotation\ValidateUser';
private $router;
private $session;
private $sc;
private $container;
public function __construct(Reader $reader, Router $rou, Session $session, SecurityContext $sc, Container $cont)
{
/** #var AnnotationReader $reader */
$this->reader = $reader;
$this->router = $rou;
$this->session = $session;
$this->sc = $sc; //security.context
$this->container = $cont; //container
}
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
$class_name = get_class($event->getController()[0]);
$method_name = $event->getController()[1];
dump($class_name); // "Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController"
dump($method_name);
$method = new \ReflectionMethod($class_name, $method_name);
dump('method'); dump($method);
// Read the annotation
$annotation = $this->reader->getMethodAnnotation($method, $this->annotation_name);
dump($annotation);//null
if (!is_null($annotation)) {
// Retrieve the validation group from the annotation, and try to
// validate the user
$validation_group = $annotation->getValidationGroup();
dump($validation_group);
$user = $this->container->get('security.token_storage')->getToken()->getUser();
dump($user);
$validator = $this->container->get('validator');
dump($validator);
$errors = $validator->validate($user);
dump($errors);
//original: $errors = $this->validator->validate($user, $validation_group);
if (count($errors)) {
$event->setController(function(){
$this->session->getFlashBag()->add('warning', 'You must fill in your phone number before joining a meetup.');
return new RedirectResponse($this->router->generate(
'user_edit',
array ('id' => '1') ) );
});
}
}
}
}
C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Security\Annotation\ValidateUser.php
<?php
namespace Yoda\UserBundle\Security\Annotation;
// Extending Symfony 2
// annotation itself ...\src\Yoda\UserBundle\Security\Annotation\ValidateUSer.php
// used in class ...src\Yoda\UserBundle\Entity\User.php
// readed/analysed by ...src\Yoda\UserBundle\Security\Annotation\AnnotationServices\AnnotationDriver::loadMetadataForClass
/**
* #Annotation
*/
class ValidateUser
{
private $validation_group;
public function __construct(array $parameters)
{
$this->validation_group = $parameters['value'];
}
public function getValidationGroup()
{
return $this->validation_group;
}
}
C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Resources\config\services.yml
yoda.user.security.valid_user_custom:
class: Yoda\UserBundle\Security\ValidUserListenerCustom
arguments: [#annotation_reader, #router, #session, #security.context, #service_container]
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onKernelController }
Usage of custom annotation "ValidateUser" to check if user, who tries to join the event, has mobile number on his profile.
url: http://127.0.0.1:8000/events/5/join4
C:\Bitnami\wampstack-5.5.30-0\sym_prog\star\src\Yoda\UserBundle\Controller\DefaultController.php
<?php ...
class DefaultController extends Controller
{ ...
/**
* #Route("/events/{event_id}/join4")
* #Template()
* #ValidateUser("join_event")
*/
public function join4Action($event_id) {
//Chapter 4
$reader = $this->get('annotation_reader');
$method = new \ReflectionMethod(get_class($this), 'join4Action');
$annotation_name = 'Yoda\UserBundle\Security\Annotation\ValidateUser';
$annotation = $reader->getMethodAnnotations($method);
//Chapter 1
$em = $this->getDoctrine()->getManager();
$meetup = $em->getRepository('EventBundle:Event')->find($event_id);
$form = $this->createForm(new JoinEventType(), $meetup, array(
'action' => '',
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Join'));
$form->handleRequest($this->get('request'));
//Do not know how to make it to work, chec later
//$user = $this->get('security.context')->getToken()->getUser();
$user = $em->getRepository('UserBundle:User')->find('1');
if ($form->isValid()) {
$meetup->addAttendee($user);
$this->get('event_dispatcher')->dispatch(MeetupEvents::MEETUP_JOIN, new MeetupEvent($user, $meetup));
$em->flush();
}
$form = $form->createView();
return compact('meetup', 'user', 'form');
}
I am using Doctrine 2.4.6 in my Symfony 2.6.1 project. The problem is that changes made to entity in preUpdate callback are not saved in database. Code follows:
class MyListener {
public function preUpdate(PreUpdateEventArgs $args) {
$entity = $args->getEntity();
$args->setNewValue('name', 'test');
// echo $args->getNewValue('name'); --> prints 'test'
}
}
class DefaultController extends Controller {
/**
* #Route("/commit", name="commit")
*/
public function commitAction(Request $request) {
$content = $request->getContent();
$serializer = $this->get('jms_serializer');
/* #var $serializer \JMS\Serializer\Serializer */
$em = $this->getDoctrine()->getManager();
/* #var $em \Doctrine\Orm\EntityManagerInterface */
$persons = $serializer->deserialize($content, 'ArrayCollection<AppBundle\Entity\Person>', 'json');
/* #var $persons \AppBundle\Entity\Person[] */
foreach($persons as $person) {
$em->merge($person);
}
$em->flush();
return new JsonResponse($serializer->serialize($persons, 'json'));
// Person name is NOT 'test' here.
}
}
The preUpdate doesn't allow you to make changes to your entities. You can only use the computed change-set passed to the event to modify primitive field values. I bet if you check the database you'll see that the Person entities did get updated, you just won't see them in the $persons variable until the next time you manually retrieve them.
What you'll have to do after the flush is retrieve the entities from the database to see their updates values:
$em->flush();
$personIds = array_map(function($person) { return $person->getId(); }, $persons);
$updatedPersons = $em->getRepository('AppBundle:Person')->findById($personIds);
return new JsonResponse($serializer->serialize($updatedPersons, 'json'));
I've been googling as crazy the last days trying to figure out (with no success) how override a SonataAdmin action to capture the session username and save it in the foreign key field.
AttachmentAdminController class:
<?php
namespace Application\Sonata\UserBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
#use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\UserBundle\Entity\User;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bridge\Monolog\Logger;
use Mercury\CargoRecognitionBundle\Entity\Attachment;
class AttachmentAdminController extends Controller
{
/**
* (non-PHPdoc)
* #see Sonata\AdminBundle\Controller.CRUDController::createAction()
*/
public function createAction()
{
$result = parent::createAction();
if ($this->get('request')->getMethod() == 'POST')
{
$flash = $this->get('session')->getFlash('sonata_flash_success');
if (!empty($flash) && $flash == 'flash_create_success')
{
#$userManager = $this->container->get('fos_user.user_manager');
#$user = $this->container->get('context.user');
#$userManager = $session->get('username');
$user = $this->container->get('security.context')->getToken()->getUser()->getUsername();
$attachment = new Attachment();
$attachment->setPath('/tmp/image.jpg');
$attachment->setNotes('nothing interesting to say');
$attachment->getSystemUser($user);
$em = $this->getDoctrine()->getEntityManager();
$em->persist($product);
$em->flush();
}
}
return $result;
}
}
service attachment:
mercury.cargo_recognition.admin.attachment:
class: Mercury\CargoRecognitionBundle\Admin\AttachmentAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: General, label: Attachments }
arguments: [ null, Mercury\CargoRecognitionBundle\Entity\Attachment, "SonataAdminBundle:CRUD" ]
Seems to me as the actionController() is been ignored by SonataAdminBundle (and maybe the whole class file), because there's not error messages at all, but I don't know why. Actually, I'm not sure if I'm fetching the username from the session.
I really need a good tutorial about this, but seems like any information I get about this is obsolete in some aspect. By the way, I'm using Symfony 2.0.16
Finally I got to the solution. I'm sure there are some others (like using event listeners, for example, that seems to be simpler), but right now it's the best I could find (it works, and that's what matters).
I was trying to override the createAction() based on examples that I found in another forum thread, but I was getting two records in the table instead of one only. The most important thing was overriding the WHOLE action method and put the custom code in it.
Controller:
<?php
namespace Mercury\CargoRecognitionBundle\Controller;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bridge\Monolog\Logger;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Application\Sonata\UserBundle\Entity\User;
use Mercury\CargoRecognitionBundle\Entity\Attachment;
use Mercury\CargoRecognitionBundle\Entity\SystemUser;
use Mercury\CargoRecognitionBundle\Repository\SystemUserRepository;
class AttachmentAdminController extends Controller
{
/**
* Set the system user ID
*/
private function updateFields($object)
{
$userName = $this->container->get('security.context')
->getToken()
->getUser()
->getUsername();
$user = $this->getDoctrine()
->getRepository('ApplicationSonataUserBundle:User')
->findOneByUsername($userName);
$object->setSystemUser($user);
return $object;
}
/**
* (non-PHPdoc)
* #see Sonata\AdminBundle\Controller.CRUDController::createAction()
*/
public function createAction()
{
// the key used to lookup the template
$templateKey = 'edit';
if (false === $this->admin->isGranted('CREATE')) {
throw new AccessDeniedException();
}
$object = $this->admin->getNewInstance();
$object = $this->updateFields($object);
// custom method
$this->admin->setSubject($object);
$form = $this->admin->getForm();
$form->setData($object);
if ($this->get('request')->getMethod() == 'POST') {
$form->bindRequest($this->get('request'));
$isFormValid = $form->isValid();
// persist if the form was valid and if in preview mode the preview was approved
if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
$this->admin->create($object);
if ($this->isXmlHttpRequest()) {
return $this->renderJson(array(
'result' => 'ok',
'objectId' => $this->admin->getNormalizedIdentifier($object)
));
}
$this->get('session')->setFlash('sonata_flash_success','flash_create_success');
// redirect to edit mode
return $this->redirectTo($object);
}
// show an error message if the form failed validation
if (!$isFormValid) {
$this->get('session')->setFlash('sonata_flash_error', 'flash_create_error');
} elseif ($this->isPreviewRequested()) {
// pick the preview template if the form was valid and preview was requested
$templateKey = 'preview';
}
}
$view = $form->createView();
// set the theme for the current Admin Form
$this->get('twig')->getExtension('form')->setTheme($view, $this->admin->getFormTheme());
return $this->render($this->admin->getTemplate($templateKey), array(
'action' => 'create',
'form' => $view,
'object' => $object,
));
}
}
Service for the controller:
mercury.cargo_recognition.admin.attachment:
class: Mercury\CargoRecognitionBundle\Admin\AttachmentAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: General, label: Attachments }
arguments: [ null, Mercury\CargoRecognitionBundle\Entity\Attachment, "MercuryCargoRecognitionBundle:AttachmentAdmin" ]
I took the solution from the following sites:
Sonata-Users,
Symfony framework forums,
(And the Sonata Project documentation)
It might be useful to override only the preCreate hook with your own logic:
/**
* This method can be overloaded in your custom CRUD controller.
* It's called from createAction.
*
* #param mixed $object
*
* #return Response|null
*/
protected function preCreate(Request $request, $object)
{
}