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

Enhancement: Introduces PagerInterface::isDeterministic (refs #8164) #8205

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/Datagrid/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,9 @@ final protected function setLastPage(int $page): void
{
$this->lastPage = $page;
}

public function isDeterministic(): bool
{
return true;
}
}
2 changes: 2 additions & 0 deletions src/Datagrid/PagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ public function setMaxPageLinks(int $maxPageLinks): void;
* Returns the maximum number of page numbers.
*/
public function getMaxPageLinks(): int;

public function isDeterministic(): bool;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea but it's a BC break to add a method in an interface.

You have to do like this

* @method array getFormOptions();
* @method bool|null showFilter();
* @method array getLabelTranslationParameters();
* @method bool withAdvancedFilter();

By just adding a @method and it will be mandatory in next major.

}
5 changes: 5 additions & 0 deletions src/Datagrid/SimplePager.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ public function getThreshold(): int
{
return $this->threshold;
}

public function isDeterministic(): bool
{
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is maybe something to compute, because if we are on the last page and there is no next page, we know the exact number of result and we can return true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds legit. I'll return this dynamically depending on currently known information!

}
}
2 changes: 1 addition & 1 deletion src/Resources/views/CRUD/base_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ file that was distributed with this source code.
<label class="checkbox" for="{{ admin.uniqid }}_all_elements">
<input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements">
{{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
({{ admin.datagrid.pager.countResults() }})
({{ admin.datagrid.pager.countResults() }}{% if not admin.datagrid.pager.deterministic %}+{% endif %})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the method is not mandatory, we might need an internal twig extension

public function isDeterministic(PagerInterface $pager): bool
{
     if (!method_exist($pager, 'isDeterministic')) {
         return true;
     }

     return $pager->isDeterministic();
}

</label>

<select name="action" style="width: auto; height: auto" class="form-control">
Expand Down
Loading