| Conditions | 7 |
| Paths | 8 |
| Total Lines | 66 |
| 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 |
||
| 72 | public function getEditForm($id = null, $fields = null) |
||
| 73 | { |
||
| 74 | $config = FoxyStripeSetting::current_foxystripe_setting(); |
||
| 75 | $fields = $config->getCMSFields(); |
||
| 76 | |||
| 77 | // Tell the CMS what URL the preview should show |
||
| 78 | $home = Director::absoluteBaseURL(); |
||
| 79 | $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); |
||
| 80 | |||
| 81 | // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load |
||
| 82 | $fields->push($navField = new LiteralField( |
||
| 83 | 'SilverStripeNavigator', |
||
| 84 | $this->getSilverStripeNavigator() |
||
| 85 | )); |
||
| 86 | $navField->setAllowHTML(true); |
||
| 87 | |||
| 88 | // Retrieve validator, if one has been setup (e.g. via data extensions). |
||
| 89 | if ($config->hasMethod('getCMSValidator')) { |
||
| 90 | $validator = $config->getCMSValidator(); |
||
| 91 | } else { |
||
| 92 | $validator = null; |
||
| 93 | } |
||
| 94 | |||
| 95 | $actions = $config->getCMSActions(); |
||
| 96 | $negotiator = $this->getResponseNegotiator(); |
||
| 97 | $form = Form::create( |
||
| 98 | $this, |
||
| 99 | 'EditForm', |
||
| 100 | $fields, |
||
| 101 | $actions, |
||
| 102 | $validator |
||
| 103 | )->setHTMLID('Form_EditForm'); |
||
| 104 | $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
||
| 105 | $request = $this->getRequest(); |
||
| 106 | if ($request->isAjax() && $negotiator) { |
||
| 107 | $result = $form->forTemplate(); |
||
| 108 | |||
| 109 | return $negotiator->respond($request, array( |
||
| 110 | 'CurrentForm' => function () use ($result) { |
||
| 111 | return $result; |
||
| 112 | }, |
||
| 113 | )); |
||
| 114 | } |
||
| 115 | }); |
||
| 116 | $form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); |
||
| 117 | $form->setAttribute('data-pjax-fragment', 'CurrentForm'); |
||
| 118 | |||
| 119 | if ($form->Fields()->hasTabSet()) { |
||
| 120 | $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
||
| 121 | } |
||
| 122 | $form->setHTMLID('Form_EditForm'); |
||
| 123 | $form->loadDataFrom($config); |
||
| 124 | $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
||
| 125 | |||
| 126 | // Use <button> to allow full jQuery UI styling |
||
| 127 | $actions = $actions->dataFields(); |
||
| 128 | if ($actions) { |
||
| 129 | /** @var FormAction $action */ |
||
| 130 | foreach ($actions as $action) { |
||
| 131 | $action->setUseButtonTag(true); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | $this->extend('updateEditForm', $form); |
||
| 136 | |||
| 137 | return $form; |
||
| 138 | } |
||
| 179 | } |