Completed
Push — master ( 1706e7...cde9f9 )
by
unknown
13:19 queued 12s
created

LegacyCollectionTypeExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildForm() 0 8 3
A getExtendedType() 0 4 1
A getExtendedTypes() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Form\Extension;
15
16
use Sonata\CoreBundle\Form\Type\CollectionType as DeprecatedCollectionType;
17
use Sonata\DoctrinePHPCRAdminBundle\Form\Listener\CollectionOrderListener;
18
use Symfony\Component\Form\AbstractTypeExtension;
19
use Symfony\Component\Form\FormBuilderInterface;
20
use Symfony\Component\Form\FormEvents;
21
22
/**
23
 * @deprecated since sonata-project/doctrine-phpcr-admin-bundle 2.x
24
 * NEXT_MAJOR: Remove this class when replace SonataCoreBundle by SonataFormExtension
25
 * Extend the sonata collection type to sort the collection so the reordering
26
 * is automatically persisted in phpcr-odm.
27
 */
28
class LegacyCollectionTypeExtension extends AbstractTypeExtension
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function buildForm(FormBuilderInterface $builder, array $options)
34
    {
35
        if ('doctrine_phpcr' !== $options['sonata_field_description']->getAdmin()->getManagerType() || !$options['sonata_field_description']->getOption('sortable')) {
36
            return;
37
        }
38
        $listener = new CollectionOrderListener($options['sonata_field_description']->getName());
39
        $builder->addEventListener(FormEvents::SUBMIT, [$listener, 'onSubmit']);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getExtendedType()
46
    {
47
        return self::getExtendedTypes()[0];
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public static function getExtendedTypes()
54
    {
55
        return [
56
            DeprecatedCollectionType::class,
57
        ];
58
    }
59
}
60