| Conditions | 3 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 41 |
| 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 |
||
| 88 | public function getCMSFields() |
||
| 89 | { |
||
| 90 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
||
| 91 | // Related Pages |
||
| 92 | $components = GridFieldConfig_RelationEditor::create(); |
||
| 93 | $components->removeComponentsByType(GridFieldAddNewButton::class); |
||
| 94 | $components->removeComponentsByType(GridFieldEditButton::class); |
||
| 95 | $components->removeComponentsByType(GridFieldFilterHeader::class); |
||
| 96 | $components->addComponent(new GridFieldSortableRows('SortOrder')); |
||
| 97 | |||
| 98 | /** @var GridFieldDataColumns $dataColumns */ |
||
| 99 | $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
||
| 100 | $dataColumns->setDisplayFields([ |
||
| 101 | 'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'), |
||
| 102 | 'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type') |
||
| 103 | ]); |
||
| 104 | |||
| 105 | $fields->findOrMakeTab( |
||
| 106 | 'Root.RelatedPages', |
||
| 107 | _t(__CLASS__ . '.RelatedPages', 'Related pages') |
||
| 108 | ); |
||
| 109 | $fields->addFieldToTab( |
||
| 110 | 'Root.RelatedPages', |
||
| 111 | GridField::create( |
||
| 112 | 'RelatedPages', |
||
| 113 | _t(__CLASS__ . '.RelatedPages', 'Related pages'), |
||
| 114 | $this->RelatedPages(), |
||
| 115 | $components |
||
| 116 | ) |
||
| 117 | ); |
||
| 118 | |||
| 119 | // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc) |
||
| 120 | $hasMany = $this->hasMany(); |
||
| 121 | $manyMany = $this->manyMany(); |
||
| 122 | if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) { |
||
| 123 | $components = GridFieldConfig_RelationEditor::create(); |
||
| 124 | $components->removeComponentsByType(GridFieldAddNewButton::class); |
||
| 125 | $components->removeComponentsByType(GridFieldEditButton::class); |
||
| 126 | |||
| 127 | /** @var GridFieldAddExistingAutocompleter $autoCompleter */ |
||
| 128 | $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class); |
||
| 129 | $autoCompleter->setResultsFormat('$Name ($TaxonomyName)'); |
||
| 130 | |||
| 131 | /** @var GridFieldDataColumns $dataColumns */ |
||
| 132 | $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
||
| 133 | $dataColumns->setDisplayFields([ |
||
| 134 | 'Name' => _t(__CLASS__ . '.Term', 'Term'), |
||
| 135 | 'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy') |
||
| 136 | ]); |
||
| 137 | |||
| 138 | $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags')); |
||
| 139 | $fields->addFieldToTab( |
||
| 140 | 'Root.Tags', |
||
| 141 | TreeMultiselectField::create( |
||
| 142 | 'Terms', |
||
| 143 | _t(__CLASS__ . '.Terms', 'Terms'), |
||
| 144 | TaxonomyTerm::class |
||
| 145 | )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms')) |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | }); |
||
| 149 | return parent::getCMSFields(); |
||
| 150 | } |
||
| 169 |