Completed
Pull Request — master (#356)
by Christian
03:38
created

EmailShareButtonBlockService::configureEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\SeoBundle\Block\Social;
15
16
use Sonata\BlockBundle\Block\BlockContextInterface;
17
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
18
use Sonata\BlockBundle\Block\Service\EditableBlockService;
19
use Sonata\BlockBundle\Form\Mapper\FormMapper;
20
use Sonata\BlockBundle\Meta\Metadata;
21
use Sonata\BlockBundle\Meta\MetadataInterface;
22
use Sonata\BlockBundle\Model\BlockInterface;
23
use Sonata\Form\Type\ImmutableArrayType;
24
use Sonata\Form\Validator\ErrorElement;
25
use Symfony\Component\Form\Extension\Core\Type\TextType;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\OptionsResolver\OptionsResolver;
28
29
/**
30
 * This block offers a button to share current page by email.
31
 *
32
 * @author Vincent Composieux <[email protected]>
33
 */
34
class EmailShareButtonBlockService extends AbstractBlockService implements EditableBlockService
35
{
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function configureSettings(OptionsResolver $resolver): void
40
    {
41
        $resolver->setDefaults([
42
            'template' => '@SonataSeo/Block/block_email_share_button.html.twig',
43
            'subject' => null,
44
            'body' => null,
45
        ]);
46
    }
47
48
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
49
    {
50
        $this->configureEditForm($form, $block);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function configureEditForm(FormMapper $form, BlockInterface $block): void
57
    {
58
        $form->add('settings', ImmutableArrayType::class, [
59
            'keys' => [
60
                ['subject', TextType::class, [
61
                    'required' => false,
62
                    'label' => 'form.label_subject',
63
                ]],
64
                ['body', TextType::class, [
65
                    'required' => false,
66
                    'label' => 'form.label_body',
67
                ]],
68
            ],
69
            'translation_domain' => 'SonataSeoBundle',
70
        ]);
71
    }
72
73
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
74
    {
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function execute(BlockContextInterface $blockContext, Response $response = null): Response
81
    {
82
        $block = $blockContext->getBlock();
83
        $settings = array_merge($blockContext->getSettings(), $block->getSettings());
84
85
        return $this->renderResponse($blockContext->getTemplate(), [
86
            'block' => $blockContext->getBlock(),
87
            'settings' => $settings,
88
        ], $response);
89
    }
90
91
    public function getMetadata(): MetadataInterface
92
    {
93
        return new Metadata('sonata.seo.block.email.share_button', null, null, 'SonataSeoBundle', [
94
            'class' => 'fa fa-envelope-o',
95
        ]);
96
    }
97
}
98