Conditions | 6 |
Paths | 8 |
Total Lines | 60 |
Code Lines | 39 |
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 |
||
94 | public function Form() |
||
95 | { |
||
96 | $crumbs = $this->Breadcrumbs(); |
||
97 | |||
98 | if ($crumbs && $crumbs->count()>=2) { |
||
99 | $one_level_up = $crumbs->offsetGet($crumbs->count()-2); |
||
100 | } |
||
101 | |||
102 | $record_ids = ""; |
||
103 | $query_string = ""; |
||
104 | $recordList = $this->getRecordIDList(); |
||
105 | |||
106 | foreach ($this->getRecordIDList() as $id) { |
||
107 | $record_ids .= $id . ','; |
||
108 | $query_string .= "records[]={$id}&"; |
||
109 | } |
||
110 | |||
111 | // Cut off the last 2 parts of the string |
||
112 | $record_ids = substr($record_ids, 0, -1); |
||
113 | $query_string = substr($query_string, 0, -1); |
||
114 | |||
115 | $form = new Form( |
||
116 | $this, |
||
117 | 'Form', |
||
118 | $fields = FieldList::create( |
||
119 | HiddenField::create("RecordIDs", "", $record_ids), |
||
120 | DropdownField::create( |
||
121 | "ContactListID", |
||
122 | _t("Contacts.ChooseList", "Choose a list"), |
||
123 | ContactList::get()->map() |
||
124 | )->setEmptyString(_t("Contacts.SelectList", "Select a List")) |
||
125 | ), |
||
126 | $actions = FieldList::create( |
||
127 | FormAction::create('doAddToList', _t("Contacts.Add", 'Add')) |
||
128 | ->setAttribute('id', 'bulkEditingSaveBtn') |
||
129 | ->addExtraClass('btn btn-success') |
||
130 | ->setAttribute('data-icon', 'accept') |
||
131 | ->setUseButtonTag(true), |
||
132 | |||
133 | FormAction::create('Cancel', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.CANCEL_BTN_LABEL', 'Cancel')) |
||
134 | ->setAttribute('id', 'bulkEditingUpdateCancelBtn') |
||
135 | ->addExtraClass('btn btn-danger cms-panel-link') |
||
136 | ->setAttribute('data-icon', 'decline') |
||
137 | ->setAttribute('href', $one_level_up->Link) |
||
138 | ->setUseButtonTag(true) |
||
139 | ->setAttribute('src', '') |
||
140 | ) |
||
141 | ); |
||
142 | |||
143 | if ($crumbs && $crumbs->count() >= 2) { |
||
144 | $form->Backlink = $one_level_up->Link; |
||
145 | } |
||
146 | |||
147 | // override form action URL back to bulkEditForm |
||
148 | // and add record ids GET var |
||
149 | $form->setFormAction( |
||
150 | $this->Link('Form?records[]='.implode('&', $recordList)) |
||
151 | ); |
||
152 | |||
153 | return $form; |
||
154 | } |
||
230 |