| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Smart\ContentBundle\Admin\Extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Cocur\Slugify\Slugify; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Sonata\AdminBundle\Admin\AbstractAdminExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Sonata\AdminBundle\Admin\AdminInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Sonata\AdminBundle\Form\FormMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Sonata\AdminBundle\Show\ShowMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Nicolas Bastien <[email protected]> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | class SeoExtension extends AbstractAdminExtension | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function configureFormFields(FormMapper $form) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             ->tab('tab.label_seo') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |                 ->with('fieldset.label_routing') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                     ->add('url', null, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                         'required' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |                         'help' => 'url.help' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                     ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 ->with('fieldset.label_metadata') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                     ->add('seoDescription', null, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                         'attr' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                             'rows' => 5 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                         ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                     ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                     ->add('customMetaTags', null, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                         'attr' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                             'rows' => 5 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                         'help' => 'custom_metatags.help' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                     ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * {@inheritDoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function configureShowFields(ShowMapper $show) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $show | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             ->tab('tab.label_seo') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 ->with('fieldset.label_routing') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                     ->add('url', null, ['label' => 'form.label_url']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 ->with('fieldset.label_metadata') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     ->add('seoDescription', null, ['label' => 'form.label_seo_description']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                     ->add('customMetaTags', null, ['label' => 'form.label_custom_meta_tags']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * {@inheritDoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function prePersist(AdminInterface $admin, $object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         if (null === $object->getUrl()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             $slugify = new Slugify(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             $object->setUrl($slugify->slugify($object->__toString())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |      * {@inheritDoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     public function preUpdate(AdminInterface $admin, $object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->prePersist($admin, $object); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  |