Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by any field #2008

Merged
merged 1 commit into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Controller/Backend/ListingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function overview(Query $query, string $contentType = ''): Response
'records' => $records,
'sortBy' => $this->getFromRequest('sortBy'),
'filterValue' => $this->getFromRequest('filter'),
'filterKey' => $this->getFromRequest('filterKey'),
]);
}
}
3 changes: 2 additions & 1 deletion src/Controller/TwigAwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ public function createPager(Query $query, string $contentType, int $pageSize, st
}

if ($this->request->get('filter')) {
$params['anyField'] = '%' . $this->getFromRequest('filter') . '%';
$key = $this->request->get('filterKey', 'anyField');
$params[$key] = '%' . $this->getFromRequest('filter') . '%';
}

if ($this->request->get('taxonomy')) {
Expand Down
10 changes: 10 additions & 0 deletions templates/content/listing.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@
<input class="form-control" type="text" name="filter" id="content-filter" value="{{ filterValue }}"
placeholder="{{ 'listing.placeholder_filter'|trans }}"/>
</p>

<p>
<label for="filterKey">{{ 'listing.title_filterby_field'|trans }}</label>:
<select name="filterKey" class="form-control">
<option value="anyField"></option>
{% for name, field in contentType.fields %}
<option value="{{ name }}" {% if name == filterKey|default %}selected {% endif %}>{{ field.label }}</option>
{% endfor %}
</select>
</p>
</div>

{{ macro.button('listing.button_filter', 'filter', 'tertiary mb-0', {'type': 'submit'}) }}
Expand Down
6 changes: 6 additions & 0 deletions translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2373,5 +2373,11 @@
<target>Select …</target>
</segment>
</unit>
<unit id="fAmcKUQ" name="listing.title_filterby_field">
<segment>
<source>listing.title_filterby_field</source>
<target>Filter by field</target>
</segment>
</unit>
</file>
</xliff>