1 | <?php |
||
6 | use SilverStripe\Forms\TextareaField; |
||
7 | |||
8 | /** |
||
9 | * Class EmbedCodeBlock |
||
10 | */ |
||
11 | View Code Duplication | class EmbedCodeBlock extends Block |
|
|
|||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @return string |
||
16 | */ |
||
17 | public function singular_name() |
||
21 | |||
22 | /** |
||
23 | * @return string |
||
24 | */ |
||
25 | public function plural_name() |
||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private static $description = 'Block providing ability to embed code (generally javascript)'; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private static $db = [ |
||
38 | 'Code' => 'HTMLText', |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * @return \FieldList |
||
43 | */ |
||
44 | public function getCMSFields() |
||
45 | { |
||
46 | $fields = parent::getCMSFields(); |
||
47 | |||
48 | $fields->replaceField( |
||
49 | 'Code', |
||
50 | TextareaField::create('Code') |
||
51 | ->setTitle('Embed Code') |
||
52 | ); |
||
53 | |||
57 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.