limit categories to owned one
This commit is contained in:
parent
d772f478b5
commit
b386d886e6
@ -3,7 +3,15 @@
|
|||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
label{
|
||||||
|
&.required{
|
||||||
|
&:after{
|
||||||
|
content: "*";
|
||||||
|
color: red;
|
||||||
|
margin-left: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
table {
|
table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ class ProductController extends Controller {
|
|||||||
public function newAction( Request $request ) {
|
public function newAction( Request $request ) {
|
||||||
$product = new Product();
|
$product = new Product();
|
||||||
$product->setUser( $this->getUser() );
|
$product->setUser( $this->getUser() );
|
||||||
|
$product->setPrice( 1 );
|
||||||
|
$product->setStockCount( 10 );
|
||||||
$form = $this->createForm( 'AppBundle\Form\ProductType', $product );
|
$form = $this->createForm( 'AppBundle\Form\ProductType', $product );
|
||||||
$form->handleRequest( $request );
|
$form->handleRequest( $request );
|
||||||
|
|
||||||
|
@ -2,11 +2,23 @@
|
|||||||
|
|
||||||
namespace AppBundle\Form;
|
namespace AppBundle\Form;
|
||||||
|
|
||||||
|
use AppBundle\Entity\ProductCategory;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Category;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\Form\FormEvent;
|
||||||
|
use Symfony\Component\Form\FormEvents;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
class ProductType extends AbstractType {
|
class ProductType extends AbstractType {
|
||||||
|
private $security;
|
||||||
|
|
||||||
|
public function __construct( Security $security ) {
|
||||||
|
$this->security = $security;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -16,10 +28,29 @@ class ProductType extends AbstractType {
|
|||||||
null,
|
null,
|
||||||
[ 'label' => 'URL pour image' ] )
|
[ 'label' => 'URL pour image' ] )
|
||||||
->add( 'stockCount' )
|
->add( 'stockCount' )
|
||||||
->add( 'price' )
|
->add( 'price')
|
||||||
->add( 'comment' )
|
->add( 'comment' );
|
||||||
->add( 'category' )// ->add( 'user' )
|
$user = $this->security->getUser();
|
||||||
;
|
if ( ! $user ) {
|
||||||
|
throw new \LogicException(
|
||||||
|
'The SellRecordType cannot be used without an authenticated user!'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$builder->addEventListener( FormEvents::PRE_SET_DATA,
|
||||||
|
function ( FormEvent $event ) {
|
||||||
|
$form = $event->getForm();
|
||||||
|
|
||||||
|
$categories = $this->security->getUser()->getCategories();
|
||||||
|
// ... add a choice list of friends of the current application user
|
||||||
|
$form->add( 'category',
|
||||||
|
EntityType::class,
|
||||||
|
[
|
||||||
|
'class' => 'AppBundle:ProductCategory',
|
||||||
|
'placeholder' => '--- catégories ---',
|
||||||
|
'choices' => $categories,
|
||||||
|
] );
|
||||||
|
} );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,16 +2,29 @@
|
|||||||
|
|
||||||
namespace AppBundle\Form;
|
namespace AppBundle\Form;
|
||||||
|
|
||||||
|
use AppBundle\Entity\Product;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Category;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
class SellRecordType extends AbstractType {
|
class SellRecordType extends AbstractType {
|
||||||
|
|
||||||
|
private $security;
|
||||||
|
|
||||||
|
public function __construct(Security $security)
|
||||||
|
{
|
||||||
|
$this->security = $security;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function buildForm( FormBuilderInterface $builder, array $options ) {
|
public function buildForm( FormBuilderInterface $builder, array $options ) {
|
||||||
$builder->add( 'products' );
|
$builder->add( 'products' );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user