Skip to content

Commit

Permalink
refactor: use a sub-array with actual data versus a weird key/value s…
Browse files Browse the repository at this point in the history
…etup.
  • Loading branch information
josegonzalez committed Jun 27, 2017
1 parent 8d0204e commit 212013b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
34 changes: 26 additions & 8 deletions docs/index-pages/customizing-the-index-page.rst
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,24 @@ to display "Finder Scope" links via the ``scaffold.index_finder_scopes``
configuration key. These are output below the action header, above the data that
is being paginated.

The ``scaffold.index_finder_scopes`` option takes an array of data, where the
"key" is the title to use for the link, and the value is the finder to link to.
The ``scaffold.index_finder_scopes`` option takes an array of finder scope data.
Each sub-array should contain ``title`` and ``finder`` parameters.

.. code-block:: php
$this->Crud->action()->config('scaffold.index_finder_scopes', [
__('All') => 'all',
__('Active') => 'active',
__('Inactive') => 'inactive',
[
'title' => __('All'),
'finder' => 'all',
],
[
'title' => __('Active'),
'finder' => 'active',
],
[
'title' => __('Inactive'),
'finder' => 'inactive',
],
]);
The ``all`` finder scope is special. This scope will be displayed by default,
Expand Down Expand Up @@ -323,9 +332,18 @@ result-set. This can be done in the mapped action as follows:
public function index()
{
$this->Crud->action()->config('scaffold.index_finder_scopes', [
__('All') => 'all',
__('Active') => 'active',
__('Inactive') => 'inactive',
[
'title' => __('All'),
'finder' => 'all',
],
[
'title' => __('Active'),
'finder' => 'active',
],
[
'title' => __('Inactive'),
'finder' => 'inactive',
],
]);
// We don't need to check for `all` as it is the default findMethod
Expand Down
5 changes: 3 additions & 2 deletions src/Template/Element/index/finder_scopes.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ if (empty($indexFinderScopes)) {
}

$finder = $this->request->query('finder');
foreach ($indexFinderScopes as $scopeTitle => $scopeFinder) {
foreach ($indexFinderScopes as $indexFinderScope) {
$scopeOptions = ['class' => 'btn btn-default btn-sm', 'role' => 'button'];
$scopeFinder = $indexFinderScope['finder'];

if (empty($finder) && $scopeFinder === 'all') {
$scopeOptions['class'] .= ' active';
Expand All @@ -17,5 +18,5 @@ foreach ($indexFinderScopes as $scopeTitle => $scopeFinder) {
if ($scopeFinder === 'all') {
$scopeUrl = [];
}
echo $this->Html->link($scopeTitle, $scopeUrl, $scopeOptions);
echo $this->Html->link($indexFinderScope['title'], $scopeUrl, $scopeOptions);
}

0 comments on commit 212013b

Please sign in to comment.