sonata-project / SonataFormatterBundle
Showing 1 of 5 files from the diff.

@@ -13,12 +13,15 @@
Loading
13 13
14 14
namespace Sonata\FormatterBundle\Block;
15 15
16 -
use Sonata\AdminBundle\Form\FormMapper;
17 16
use Sonata\BlockBundle\Block\BlockContextInterface;
18 -
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService;
17 +
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
18 +
use Sonata\BlockBundle\Block\Service\EditableBlockService;
19 +
use Sonata\BlockBundle\Form\Mapper\FormMapper;
19 20
use Sonata\BlockBundle\Meta\Metadata;
21 +
use Sonata\BlockBundle\Meta\MetadataInterface;
20 22
use Sonata\BlockBundle\Model\BlockInterface;
21 23
use Sonata\Form\Type\ImmutableArrayType;
24 +
use Sonata\Form\Validator\ErrorElement;
22 25
use Sonata\FormatterBundle\Form\Type\FormatterType;
23 26
use Symfony\Component\Form\FormBuilderInterface;
24 27
use Symfony\Component\HttpFoundation\Response;
@@ -27,7 +30,7 @@
Loading
27 30
/**
28 31
 * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
29 32
 */
30 -
final class FormatterBlockService extends AbstractAdminBlockService
33 +
final class FormatterBlockService extends AbstractBlockService implements EditableBlockService
31 34
{
32 35
    public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
33 36
    {
@@ -37,8 +40,18 @@
Loading
37 40
        ], $response);
38 41
    }
39 42
40 -
    public function buildEditForm(FormMapper $formMapper, BlockInterface $block): void
43 +
    /**
44 +
     * @deprecated since sonata-project/formatter-bundle 4.x, to be removed in 5.0.
45 +
     *
46 +
     * NEXT_MAJOR: Remove this method
47 +
     */
48 +
    public function buildEditForm(\Sonata\AdminBundle\Form\FormMapper $formMapper, BlockInterface $block): void
41 49
    {
50 +
        @trigger_error(
51 +
            sprintf('The %s method is deprecated since sonata-project/formatter-bundle 4.x, to be removed in 5.0.', __METHOD__).
52 +
            \E_USER_DEPRECATED
53 +
        );
54 +
42 55
        $formMapper->add('settings', ImmutableArrayType::class, [
43 56
            'keys' => [
44 57
                ['content', FormatterType::class, static function (FormBuilderInterface $formBuilder) {
@@ -55,6 +68,33 @@
Loading
55 68
        ]);
56 69
    }
57 70
71 +
    public function configureEditForm(FormMapper $form, BlockInterface $block): void
72 +
    {
73 +
        $form->add('settings', ImmutableArrayType::class, [
74 +
            'keys' => [
75 +
                ['content', FormatterType::class, static function (FormBuilderInterface $formBuilder) {
76 +
                    return [
77 +
                        'event_dispatcher' => $formBuilder->getEventDispatcher(),
78 +
                        'format_field' => ['format', '[format]'],
79 +
                        'source_field' => ['rawContent', '[rawContent]'],
80 +
                        'target_field' => '[content]',
81 +
                        'label' => 'form.label_content',
82 +
                    ];
83 +
                }],
84 +
            ],
85 +
            'translation_domain' => 'SonataFormatterBundle',
86 +
        ]);
87 +
    }
88 +
89 +
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
90 +
    {
91 +
        $this->configureEditForm($form, $block);
92 +
    }
93 +
94 +
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
95 +
    {
96 +
    }
97 +
58 98
    public function configureSettings(OptionsResolver $resolver): void
59 99
    {
60 100
        $resolver->setDefaults([
@@ -65,8 +105,18 @@
Loading
65 105
        ]);
66 106
    }
67 107
108 +
    /**
109 +
     * @deprecated since sonata-project/formatter-bundle 4.x, to be removed in 5.0.
110 +
     *
111 +
     * NEXT_MAJOR: Remove this method
112 +
     */
68 113
    public function getBlockMetadata($code = null): Metadata
69 114
    {
115 +
        @trigger_error(
116 +
            sprintf('The %s method is deprecated since sonata-project/formatter-bundle 4.x, to be removed in 5.0.', __METHOD__).
117 +
            \E_USER_DEPRECATED
118 +
        );
119 +
70 120
        return new Metadata(
71 121
            $this->getName(),
72 122
            null !== $code ? $code : $this->getName(),
@@ -75,4 +125,15 @@
Loading
75 125
            ['class' => 'fa fa-file-text-o']
76 126
        );
77 127
    }
128 +
129 +
    public function getMetadata(): MetadataInterface
130 +
    {
131 +
        return new Metadata(
132 +
            'sonata.formatter.block.formatter',
133 +
            null,
134 +
            null,
135 +
            'SonataFormatterBundle',
136 +
            ['class' => 'fa fa-file-text-o']
137 +
        );
138 +
    }
78 139
}
Files Complexity Coverage
src 141 42.17%
Project Totals (20 files) 141 42.17%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading