EmailShareButtonBlockService::configureEditForm()   A
last analyzed

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
final class EmailShareButtonBlockService extends AbstractBlockService implements EditableBlockService
35
{
36
    public function configureSettings(OptionsResolver $resolver): void
37
    {
38
        $resolver->setDefaults([
39
            'template' => '@SonataSeo/Block/block_email_share_button.html.twig',
40
            'subject' => null,
41
            'body' => null,
42
        ]);
43
    }
44
45
    public function configureCreateForm(FormMapper $formMapper, BlockInterface $block): void
46
    {
47
        $this->configureEditForm($formMapper, $block);
48
    }
49
50
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
51
    {
52
        $formMapper->add('settings', ImmutableArrayType::class, [
53
            'keys' => [
54
                ['subject', TextType::class, [
55
                    'required' => false,
56
                    'label' => 'form.label_subject',
57
                ]],
58
                ['body', TextType::class, [
59
                    'required' => false,
60
                    'label' => 'form.label_body',
61
                ]],
62
            ],
63
            'translation_domain' => 'SonataSeoBundle',
64
        ]);
65
    }
66
67
    public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
68
    {
69
        $block = $blockContext->getBlock();
70
        $settings = array_merge($blockContext->getSettings(), $block->getSettings());
71
72
        return $this->renderResponse($blockContext->getTemplate(), [
73
            'block' => $blockContext->getBlock(),
74
            'settings' => $settings,
75
        ], $response);
76
    }
77
78
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
79
    {
80
    }
81
82
    public function getMetadata(): MetadataInterface
83
    {
84
        return new Metadata('sonata.seo.block.pinterest.share_button', null, null, 'SonataSeoBundle', [
85
            'class' => 'fa fa-envelope-o',
86
        ]);
87
    }
88
}
89