| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 62 | public function getCMSFields() |
||
| 63 | { |
||
| 64 | $this->beforeUpdateCMSFields(function ($fields) { |
||
| 65 | $editableColumns = new GridFieldEditableColumns(); |
||
| 66 | $editableColumns->setDisplayFields([ |
||
| 67 | 'Title' => [ |
||
| 68 | 'title' => _t(__CLASS__.'.TITLE', 'Title'), |
||
| 69 | 'callback' => function ($record, $column, $grid) { |
||
| 70 | return TextField::create($column); |
||
| 71 | } |
||
| 72 | ], |
||
| 73 | 'Value' => [ |
||
| 74 | 'title' => _t(__CLASS__.'.VALUE', 'Value'), |
||
| 75 | 'callback' => function ($record, $column, $grid) { |
||
| 76 | return TextField::create($column); |
||
| 77 | } |
||
| 78 | ], |
||
| 79 | 'Default' => [ |
||
| 80 | 'title' => _t(__CLASS__.'.DEFAULT', 'Selected by default?'), |
||
| 81 | 'callback' => function ($record, $column, $grid) { |
||
| 82 | return CheckboxField::create($column); |
||
| 83 | } |
||
| 84 | ] |
||
| 85 | ]); |
||
| 86 | |||
| 87 | $optionsConfig = GridFieldConfig::create() |
||
| 88 | ->addComponents( |
||
| 89 | new GridFieldToolbarHeader(), |
||
| 90 | new GridFieldTitleHeader(), |
||
| 91 | new GridFieldOrderableRows('Sort'), |
||
| 92 | $editableColumns, |
||
| 93 | new GridFieldButtonRow(), |
||
| 94 | new GridFieldAddNewInlineButton(), |
||
| 95 | new GridFieldDeleteAction() |
||
| 96 | ); |
||
| 97 | |||
| 98 | $optionsGrid = GridField::create( |
||
| 99 | 'Options', |
||
| 100 | _t('SilverStripe\\UserForms\\Model\\EditableFormField.CUSTOMOPTIONS', 'Options'), |
||
| 101 | $this->Options(), |
||
| 102 | $optionsConfig |
||
| 103 | ); |
||
| 104 | |||
| 105 | $fields->insertAfter(Tab::create('Options', _t(__CLASS__.'.OPTIONSTAB', 'Options')), 'Main'); |
||
| 106 | $fields->addFieldToTab('Root.Options', $optionsGrid); |
||
| 107 | }); |
||
| 108 | |||
| 109 | $fields = parent::getCMSFields(); |
||
| 110 | |||
| 111 | return $fields; |
||
| 112 | } |
||
| 113 | |||
| 170 |