PHP code example of ggggino / sonataextrafields-bundle

1. Go to this page and download the library: Download ggggino/sonataextrafields-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ggggino / sonataextrafields-bundle example snippets


use Allyou\ManagementBundle\Form\Type\CustomCollectionType;

/**
 * @param FormMapper $formMapper
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('medias', CollectionBuilderType::class, array(
                'by_reference' => false,
                'wrapper_class' => 'col-xs-4',
                'formWizard' => function(FormBuilderInterface $builder) {
                    // Here you can build your wizard
                },
                'formWizardPreSetData' => function(FormEvent $event) {
                    // Here you can set particular
                },
                'formWizardPreSubmit' => function(FormEvent $event) {
                    // Here you can manipulate the model before the persist
                },
                'formWizardOnSubmit' => function(FormEvent $event) {
                    // Here you can manipulate the model after the persist
                }
            ), array(
                'edit' => 'inline',
                //'inline' => 'table',
                'sortable' => 'position',
                'admin_code' => 'app.admin.media',
            ))
    ;
}

$formMapper->add('fasce', CollectionBuilderType::class, array(
    'by_reference' => false,
    'wrapper_class' => 'col-xs-4',
    'formWizard' => function(FormBuilderInterface $builder) use ($em) {
        $companies = $em->getRepository(Company::class)->findAll();
        $companyMapped = array("Select a company" => 0);

        /** @var Ditta $value */
        foreach( $companies as $company ) {
            $companyMapped[$company->getLabel()] = $company->getId();
        }

        $builder
            ->add('company', ChoiceType::class, array(
                'choices' => $companyMapped
            ));
    },
    'formWizardOnSubmit' => function(FormEvent $event) use ($em) {
        $data = $event->getData();
        /** @var PersistentCollection $items */
        $items = $data['items'];
        $wizard = $data['wizard'];

        if( !isset($wizard['company']) || !$wizard['company'] )
            return;

        $idCompany = isset($wizard['company']) ? $wizard['company'] : null;
        $companyRef = $em->getReference(Company::class, $idCompany);

        /** @var User[] $usersInCompany */
        $usersInCompany = $em->getRepository(User::class)->findBy(array('company' => $companyRef));

        foreach($usersInCompany as $user) {
            $temp = new GiornataFascia();
            $temp->setOre(0);
            $temp->setUtente($user);

            $items->add($temp);
        }
    }
), array(
    'edit' => 'inline',
    'inline' => 'table',
    'sortable' => 'position',
    'admin_code' => 'app.admin.giornata_fascia',
));

use Allyou\ManagementBundle\Form\Type\CustomCollectionType;

/**
 * @param FormMapper $formMapper
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('medias', CustomCollectionType::class, array(
                'by_reference' => false,
                'wrapper_class' => 'col-xs-4'
            ), array(
                'edit' => 'inline',
                //'inline' => 'table',
                'sortable' => 'position',
                'admin_code' => 'app.admin.media',
            ))
    ;
}