Skip to content

Commit

Permalink
Merge pull request #126 from FriendsOfCake/viewsearch-listener
Browse files Browse the repository at this point in the history
Use filter name itself as field name.
  • Loading branch information
jippi committed May 24, 2016
2 parents 73268dc + d39c585 commit 1999f15
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/Listener/ViewSearchListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ protected function _deriveFields()
continue;
}

$searchParam = $filter->name();
$field = $filter->field() ?: $searchParam;

// Ignore multi-field filters for now
if (is_array($field)) {
continue;
}

$field = $filter->name();
$input = [];

$filterFormConfig = $filter->config();
Expand All @@ -101,37 +94,31 @@ protected function _deriveFields()
}

$input += [
'label' => Inflector::humanize(preg_replace('/_id$/', '', $searchParam)),
'label' => Inflector::humanize(preg_replace('/_id$/', '', $field)),
'required' => false,
'type' => 'text'
];

$value = $request->query($searchParam);
$value = $request->query($field);
if ($value !== null) {
$input['value'] = $value;
}

if (empty($input['options']) && $table->hasField($field)) {
if ($schema->columnType($field) === 'boolean') {
$input['options'] = ['No', 'Yes'];
$input['type'] = 'select';
}
if (empty($input['options']) && $schema->columnType($field) === 'boolean') {
$input['options'] = ['No', 'Yes'];
$input['type'] = 'select';
}

if (!empty($input['options'])) {
$input['empty'] = true;
$fields[$searchParam] = $input;
$fields[$field] = $input;
continue;
}

if (empty($input['class'])) {
$input['class'] = 'autocomplete';
}

if (empty($input['type'])) {
$input['type'] = 'text';
}

$urlArgs = [];

$fieldKeys = isset($input['fields']) ? $input['fields'] : ['id' => $field, 'value' => $field];
Expand All @@ -143,7 +130,7 @@ protected function _deriveFields()
$url = array_merge(['action' => 'lookup', '_ext' => 'json'], $urlArgs);
$input['data-url'] = Router::url($url);

$fields[$searchParam] = $input;
$fields[$field] = $input;
}
return $fields;
}
Expand Down

0 comments on commit 1999f15

Please sign in to comment.