| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SilverStripe\ElementalBlocks\Block; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SilverStripe\ElementalBlocks\Form\BlockLinkField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\Forms\FieldList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Forms\HiddenField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Forms\HTMLEditor\TinyMCEConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\View\Requirements; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class BannerBlock extends FileBlock | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private static $db = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         'Content' => 'HTMLText', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         'ImageLink' => 'Link', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         'CallToActionLink' => 'Link', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private static $singular_name = 'banner'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     private static $plural_name = 'banners'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function getType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         return _t(__CLASS__ . '.BlockType', 'Banner'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     public function getCMSFields() | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->beforeUpdateCMSFields(function (FieldList $fields) { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             // Remove default scaffolded relationship fields | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |             $fields->removeByName('ImageLinkID'); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             $fields->removeByName('CallToActionLinkID'); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             // Create hidden inputs for JSON input from the "insert link" modal | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             $fields->addFieldsToTab('Root.Main', [ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |                 HiddenField::create('ImageLinkData'), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |                 HiddenField::create('CallToActionLinkData'), | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |             ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             // Move the file upload field to be before the content | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |             $upload = $fields->fieldByName('Root.Main.File'); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             $fields->insertBefore('Content', $upload); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             // Move the Image Link to underneath the file upload field | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             $imageLink = $fields->fieldByName('Root.Main.ImageLink'); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             $fields->insertBefore('Content', $imageLink); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             // Set the height of the content fields | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             $fields->fieldByName('Root.Main.Content')->setRows(5); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         }); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         // Ensure TinyMCE's javascript is loaded before the blocks overrides | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         Requirements::javascript(TinyMCEConfig::get('cms')->getScriptURL()); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         Requirements::javascript('silverstripe/elemental-blocks:client/dist/js/bundle.js'); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         Requirements::css('silverstripe/elemental-blocks:client/dist/styles/bundle.css'); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         return parent::getCMSFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  | 
            
                        
This check marks private properties in classes that are never used. Those properties can be removed.