Conditions | 4 |
Paths | 8 |
Total Lines | 78 |
Code Lines | 50 |
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 |
||
57 | public function getHTMLFragments($gridField) |
||
58 | { |
||
59 | $fields = ArrayList::create(); |
||
60 | $state = $gridField->State->UserFormsGridField; |
||
61 | |||
62 | $selectedField = $state->filter; |
||
63 | $selectedValue = $state->value; |
||
64 | |||
65 | // show dropdown of all the fields available from the submitted form fields |
||
66 | // that have been saved. Takes the titles from the currently live form. |
||
67 | $columnField = DropdownField::create('FieldNameFilter', ''); |
||
68 | $columnField->setSource($this->columns); |
||
69 | $columnField->setEmptyString(_t(__CLASS__.'.FILTERSUBMISSIONS', 'Filter Submissions..')); |
||
70 | $columnField->setHasEmptyDefault(true); |
||
71 | $columnField->setValue($selectedField); |
||
72 | |||
73 | $valueField = TextField::create('FieldValue', '', $selectedValue); |
||
74 | |||
75 | $columnField->addExtraClass('ss-gridfield-sort'); |
||
76 | $columnField->addExtraClass('no-change-track'); |
||
77 | |||
78 | $valueField->addExtraClass('ss-gridfield-sort'); |
||
79 | $valueField->addExtraClass('no-change-track'); |
||
80 | $valueField->setAttribute( |
||
81 | 'placeholder', |
||
82 | _t(__CLASS__.'.WHEREVALUEIS', 'where value is..') |
||
83 | ); |
||
84 | |||
85 | $fields->push(FieldGroup::create(CompositeField::create( |
||
86 | $columnField, |
||
87 | $valueField |
||
88 | ))); |
||
89 | |||
90 | $fields->push(FieldGroup::create(CompositeField::create( |
||
91 | $start = DateField::create('StartFilter', _t(__CLASS__.'.FROM', 'From')), |
||
92 | $end = DateField::create('EndFilter', _t(__CLASS__.'.TILL', 'Till')) |
||
93 | ))); |
||
94 | |||
95 | foreach (array($start, $end) as $date) { |
||
96 | $date->setDateFormat(DBDate::ISO_DATE); |
||
97 | $date->addExtraClass('no-change-track'); |
||
98 | } |
||
99 | |||
100 | if ($state->end) { |
||
101 | $end->setValue($state->end); |
||
102 | } |
||
103 | if ($state->start) { |
||
104 | $start->setValue($state->start); |
||
105 | } |
||
106 | |||
107 | |||
108 | $fields->push($actions = FieldGroup::create( |
||
109 | GridField_FormAction::create($gridField, 'filter', false, 'filter', null) |
||
110 | ->addExtraClass('ss-gridfield-button-filter btn btn-primary') |
||
111 | ->setTitle(_t(__CLASS__.'.FILTER', "Filter")) |
||
112 | ->setAttribute('title', _t(__CLASS__.'.FILTER', "Filter")) |
||
113 | ->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField), |
||
114 | GridField_FormAction::create($gridField, 'reset', false, 'reset', null) |
||
115 | ->addExtraClass('ss-gridfield-button-close btn ') |
||
116 | ->setTitle(_t(__CLASS__.'.RESET', "Reset")) |
||
117 | ->setAttribute('title', _t(__CLASS__.'.RESET', "Reset")) |
||
118 | ->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField) |
||
119 | )); |
||
120 | |||
121 | $actions->addExtraClass('filter-buttons'); |
||
122 | $actions->addExtraClass('no-change-track'); |
||
123 | |||
124 | $colSpan = 2 + count($gridField->getConfig()->getComponentByType(GridFieldDataColumns::class) |
||
125 | ->getDisplayFields($gridField)); |
||
126 | |||
127 | $forTemplate = ArrayData::create(array( |
||
128 | 'Fields' => $fields, |
||
129 | 'ColSpan' => $colSpan |
||
130 | )); |
||
131 | |||
132 | |||
133 | return array( |
||
134 | 'header' => $forTemplate->renderWith(UserFormsGridFieldFilterHeader::class . '_Row') |
||
135 | ); |
||
173 |