| 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\ChoiceType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Symfony\Component\Form\Extension\Core\Type\IntegerType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Symfony\Component\Form\Extension\Core\Type\TextType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Symfony\Component\Form\Extension\Core\Type\UrlType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Symfony\Component\HttpFoundation\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use Symfony\Component\OptionsResolver\OptionsResolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * Pinterest pin button integration. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * @see http://fr.business.pinterest.com/widget-builder/#do_pin_it_button | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  * @author Vincent Composieux <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | class PinterestPinButtonBlockService extends AbstractBlockService implements EditableBlockService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function configureSettings(OptionsResolver $resolver): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $resolver->setDefaults([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             'template' => '@SonataSeo/Block/block_pinterest_pin_button.html.twig', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             'size' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             'shape' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'url' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             'image' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             'description' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     public function configureCreateForm(FormMapper $form, BlockInterface $block): void | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $this->configureEditForm($form, $block); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     public function configureEditForm(FormMapper $form, BlockInterface $block): void | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $form->add('settings', ImmutableArrayType::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             'keys' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                 ['url', UrlType::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                     'required' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |                     'label' => 'form.label_url', | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |                 ]], | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                 ['image', TextType::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |                     'required' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |                     'label' => 'form.label_image', | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |                 ]], | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |                 ['description', TextType::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |                     'required' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |                     'label' => 'form.label_description', | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |                 ]], | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |                 ['size', IntegerType::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |                     'required' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |                     'label' => 'form.label_size', | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |                 ]], | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |                 ['shape', ChoiceType::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |                     'required' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |                     'choices' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |                         'rectangular' => 'form.label_shape_rectangular', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                         'round' => 'form.label_shape_round', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                     ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                     'label' => 'form.label_shape', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 ]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             'translation_domain' => 'SonataSeoBundle', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function validate(ErrorElement $errorElement, BlockInterface $block): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     public function execute(BlockContextInterface $blockContext, Response $response = null): Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $block = $blockContext->getBlock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $settings = array_merge($blockContext->getSettings(), $block->getSettings()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         return $this->renderResponse($blockContext->getTemplate(), [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             'block' => $blockContext->getBlock(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             'settings' => $settings, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         ], $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     public function getMetadata(): MetadataInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         return new Metadata('sonata.seo.block.pinterest.pin_button', null, null, 'SonataSeoBundle', [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             'class' => 'fa fa-envelope-o', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |  |