| Conditions | 5 |
| Paths | 8 |
| Total Lines | 89 |
| Code Lines | 66 |
| 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 |
||
| 38 | public function getCMSFields() |
||
| 39 | { |
||
| 40 | $fields = parent::getCMSFields(); |
||
| 41 | |||
| 42 | $subsites = DataObject::get(Subsite::class); |
||
| 43 | if (!$subsites) { |
||
| 44 | $subsites = new ArrayList(); |
||
| 45 | } else { |
||
| 46 | $subsites = ArrayList::create($subsites->toArray()); |
||
| 47 | } |
||
| 48 | |||
| 49 | $subsites->push(new ArrayData(['Title' => 'Main site', 'ID' => 0])); |
||
| 50 | |||
| 51 | $fields->addFieldToTab( |
||
| 52 | 'Root.Main', |
||
| 53 | DropdownField::create( |
||
| 54 | 'CopyContentFromID_SubsiteID', |
||
| 55 | _t(__CLASS__ . '.SubsiteField', 'Subsite'), |
||
| 56 | $subsites->map('ID', 'Title') |
||
| 57 | )->addExtraClass('subsitestreedropdownfield-chooser no-change-track'), |
||
| 58 | 'CopyContentFromID' |
||
| 59 | ); |
||
| 60 | |||
| 61 | // Setup the linking to the original page. |
||
| 62 | $pageSelectionField = new SubsitesTreeDropdownField( |
||
| 63 | 'CopyContentFromID', |
||
| 64 | _t('SilverStripe\\CMS\\Model\\VirtualPage.CHOOSE', 'Choose a page to link to'), |
||
| 65 | "SilverStripe\\CMS\\Model\\SiteTree", |
||
| 66 | 'ID', |
||
| 67 | 'MenuTitle' |
||
| 68 | ); |
||
| 69 | |||
| 70 | if (Controller::has_curr() && Controller::curr()->getRequest()) { |
||
| 71 | $subsiteID = Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID'); |
||
| 72 | $pageSelectionField->setSubsiteID($subsiteID); |
||
| 73 | } |
||
| 74 | $fields->replaceField('CopyContentFromID', $pageSelectionField); |
||
| 75 | |||
| 76 | // Create links back to the original object in the CMS |
||
| 77 | if ($this->CopyContentFromID) { |
||
| 78 | $editLink = "admin/pages/edit/show/$this->CopyContentFromID/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID; |
||
| 79 | $linkToContent = " |
||
| 80 | <a class=\"cmsEditlink\" href=\"$editLink\">" . |
||
| 81 | _t('SilverStripe\\CMS\\Model\\VirtualPage.EDITCONTENT', 'Click here to edit the content') . |
||
| 82 | '</a>'; |
||
| 83 | $fields->removeByName('VirtualPageContentLinkLabel'); |
||
| 84 | $fields->addFieldToTab( |
||
| 85 | 'Root.Main', |
||
| 86 | $linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent), |
||
| 87 | 'Title' |
||
| 88 | ); |
||
| 89 | $linkToContentLabelField->setAllowHTML(true); |
||
| 90 | } |
||
| 91 | |||
| 92 | |||
| 93 | $fields->addFieldToTab( |
||
| 94 | 'Root.Main', |
||
| 95 | TextField::create( |
||
| 96 | 'CustomMetaTitle', |
||
| 97 | $this->fieldLabel('CustomMetaTitle') |
||
| 98 | )->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')), |
||
| 99 | 'MetaTitle' |
||
| 100 | ); |
||
| 101 | $fields->addFieldToTab( |
||
| 102 | 'Root.Main', |
||
| 103 | TextareaField::create( |
||
| 104 | 'CustomMetaKeywords', |
||
| 105 | $this->fieldLabel('CustomMetaTitle') |
||
| 106 | )->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')), |
||
| 107 | 'MetaKeywords' |
||
| 108 | ); |
||
| 109 | $fields->addFieldToTab( |
||
| 110 | 'Root.Main', |
||
| 111 | TextareaField::create( |
||
| 112 | 'CustomMetaDescription', |
||
| 113 | $this->fieldLabel('CustomMetaTitle') |
||
| 114 | )->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')), |
||
| 115 | 'MetaDescription' |
||
| 116 | ); |
||
| 117 | $fields->addFieldToTab( |
||
| 118 | 'Root.Main', |
||
| 119 | TextField::create( |
||
| 120 | 'CustomExtraMeta', |
||
| 121 | $this->fieldLabel('CustomMetaTitle') |
||
| 122 | )->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')), |
||
| 123 | 'ExtraMeta' |
||
| 124 | ); |
||
| 125 | |||
| 126 | return $fields; |
||
| 127 | } |
||
| 242 |