resolution lenteur sur submit/update blogarticle (ref #180)

This commit is contained in:
afornerot 2020-09-16 09:58:57 +02:00
parent 936b6810b0
commit cb5b98237d
2 changed files with 44 additions and 22 deletions

View File

@ -26,14 +26,16 @@ class BlogarticleController extends Controller
return $this->createForm(BlogarticleType::class, $entity, [
"mode" => "update",
"access" => $access,
"user" => $this->getUser()
"user" => $this->getUser(),
'blogarticle' => $entity,
]);
}
else {
return $this->createForm(BlogarticleType::class, $entity, [
"mode" => "submit",
"access" => $access,
"user" => $this->getUser()
"user" => $this->getUser(),
'blogarticle' => $entity,
]);
}
}

View File

@ -21,6 +21,7 @@ class BlogarticleType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$user=$options['user'];
$blogarticle=$options['blogarticle'];
$builder
->add('submit', SubmitType::class, [
@ -60,6 +61,7 @@ class BlogarticleType extends AbstractType
]);
}
else {
if(!$blogarticle->getBlog()) {
$builder
->add('blog', EntityType::class, [
'label' => 'Blog associé',
@ -84,6 +86,23 @@ class BlogarticleType extends AbstractType
},
]);
}
else {
$builder
->add('blog', EntityType::class, [
'label' => 'Blog associé',
'class' => 'CadolesPortalBundle:Blog',
'choice_label' => 'name',
"disabled" => ($options["mode"]=="update"?true:false),
'placeholder' => '-- Sélectionnez un Blog --',
'query_builder' => function(EntityRepository $er) use ($blogarticle) {
$qb=$er->createQueryBuilder('blog');
return $qb->select('blog')
->where('blog.id=:blog')
->setparameter('blog',$blogarticle->getBlog()->getId());
},
]);
}
}
}
public function configureOptions(OptionsResolver $resolver)
@ -92,7 +111,8 @@ class BlogarticleType extends AbstractType
'data_class' => 'Cadoles\PortalBundle\Entity\Blogarticle',
'mode' => 'string',
'access' => 'string',
'user' => 'Cadoles\CoreBundle\Entity\User'
'user' => 'Cadoles\CoreBundle\Entity\User',
'blogarticle' => 'Cadoles\PortalBundle\Entity\Blogarticle'
]);
}
}