Skip to content

Commit

Permalink
Rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dvlpp committed Nov 22, 2024
1 parent 96ee5a1 commit 8364a9d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/guide/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ In order to make this feature work, since filters are generalized, you'll need t

## Drop filters depending on functional data

Sometimes you may want to hide a filter to the user depending on the actual data, or on other filters values. This can be achieved by using the `dropFilter()` method in your EntityList class, typically in the `getListData()` method.
Sometimes you may want to hide a filter to the user depending on the actual data, or on other filters values. This can be achieved by using the `useFilter()` method in your EntityList class, typically in the `getListData()` method.

```php
class OrderEntityList extends SharpEntityList
Expand All @@ -262,7 +262,7 @@ class OrderEntityList extends SharpEntityList
{
if ($this->queryParams->filterFor(PaymentMethodFilter::class) !== 'online') {
// No need to show the OnlinePaymentProviderFilter
$this->dropFilter(OnlinePaymentProviderFilter::class);
$this->hideFilter(OnlinePaymentProviderFilter::class);
}

// ...
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/reordering-instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Then, in your Entity List you have to configure your reorder handler:
```php
class PageEntityList extends SharpEntityList
{
// [...]
// ...

public function buildListConfig()
{
Expand All @@ -55,7 +55,7 @@ Note that you can also pass a ReorderHandler classname, or an anonymous class th

The reorder action depends on the `reorder` permission. You can define it in the [Entity Policy](entity-authorizations.md):

Sometimes you may need to restrict the reorder action depending on the actual data, or on some filters values. This can be achieved by using the `forbidReorder()` method in your EntityList class, typically in the `getListData()` method.
Sometimes you may need to restrict the reorder action depending on the actual data, or on some filters values. This can be achieved by using the `disableReorder()` method in your EntityList class, typically in the `getListData()` method.

```php
class PostEntityList extends SharpEntityList
Expand All @@ -70,7 +70,7 @@ class PostEntityList extends SharpEntityList
public function getListData(): array|Arrayable
{
// We can’t reorder if there is a search
$this->forbidReorder($this->queryParams->hasSearch());
$this->disableReorder($this->queryParams->hasSearch());

// ...
}
Expand Down
8 changes: 4 additions & 4 deletions src/EntityList/SharpEntityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class SharpEntityList
protected ?string $multiformAttribute = null;
protected bool $searchable = false;
protected ?ReorderHandler $reorderHandler = null;
private bool $forbidsReorder = false;
private bool $disabledReorder = false;
protected ?string $defaultSort = null;
protected ?string $defaultSortDir = null;
protected bool $deleteHidden = false;
Expand Down Expand Up @@ -107,7 +107,7 @@ final public function listConfig(bool $hasShowPage = false): array
'instanceIdAttribute' => $this->instanceIdAttribute,
'multiformAttribute' => $this->multiformAttribute,
'searchable' => $this->searchable,
'reorderable' => ! is_null($this->reorderHandler) && ! $this->forbidsReorder,
'reorderable' => ! is_null($this->reorderHandler) && ! $this->disabledReorder,
'defaultSort' => $this->defaultSort,
'defaultSortDir' => $this->defaultSortDir,
'hasShowPage' => $hasShowPage,
Expand Down Expand Up @@ -195,9 +195,9 @@ final protected function getDataKeys(): array
->all();
}

final protected function forbidReorder(bool $forbidReorder = true): void
final protected function disableReorder(bool $disableReorder = true): void
{
$this->forbidsReorder = $forbidReorder;
$this->disabledReorder = $disableReorder;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Filters/HandleFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final public function filterContainer(): FilterContainer
/**
* @internal
*/
final public function dropFilter(string $filterFullClassNameOrKey): void
final public function hideFilter(string $filterFullClassNameOrKey): void
{
$this->filterContainer()->excludeFilter($filterFullClassNameOrKey);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/EntityList/SharpEntityListFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public function values(): array

public function getListData(): array
{
$this->dropFilter('test');
$this->hideFilter('test');

return [];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/EntityList/SharpEntityListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public function reorder(array $ids): void {}
->and($list->reorderHandler())->toBeInstanceOf(ReorderHandler::class);
});

it('allows to borbid a configured reorder handler', function () {
it('allows to disable a configured reorder handler', function () {
$list = new class() extends FakeSharpEntityList
{
public function buildListConfig(): void
Expand All @@ -309,7 +309,7 @@ public function reorder(array $ids): void {}

public function getListData(): array|Arrayable
{
$this->forbidReorder();
$this->disableReorder();

return [];
}
Expand Down

0 comments on commit 8364a9d

Please sign in to comment.