backports murph-skeleton
This commit is contained in:
parent
059d67cdb9
commit
1128b1fb9a
|
@ -207,9 +207,10 @@ abstract class CrudController extends AdminController
|
||||||
protected function applySort(string $context, RepositoryQuery $query, Request $request)
|
protected function applySort(string $context, RepositoryQuery $query, Request $request)
|
||||||
{
|
{
|
||||||
$configuration = $this->getConfiguration();
|
$configuration = $this->getConfiguration();
|
||||||
|
$defaultSort = $configuration->getDefaultSort($context);
|
||||||
|
|
||||||
$name = $request->query->get('_sort');
|
$name = $request->query->get('_sort', $defaultSort['label'] ?? null);
|
||||||
$direction = strtolower($request->query->get('_sort_direction'));
|
$direction = strtolower($request->query->get('_sort_direction', $defaultSort['direction'] ?? 'asc'));
|
||||||
|
|
||||||
if (!in_array($direction, ['asc', 'desc'])) {
|
if (!in_array($direction, ['asc', 'desc'])) {
|
||||||
$direction = 'asc';
|
$direction = 'asc';
|
||||||
|
@ -238,6 +239,8 @@ abstract class CrudController extends AdminController
|
||||||
'label' => $label,
|
'label' => $label,
|
||||||
'direction' => $direction,
|
'direction' => $direction,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace App\Core\Crud;
|
namespace App\Core\Crud;
|
||||||
|
|
||||||
|
use App\Core\Crud\Exception\CrudConfigurationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class CrudConfiguration.
|
* class CrudConfiguration.
|
||||||
*
|
*
|
||||||
|
@ -20,6 +22,7 @@ class CrudConfiguration
|
||||||
protected array $fields = [];
|
protected array $fields = [];
|
||||||
protected array $maxPerPage = [];
|
protected array $maxPerPage = [];
|
||||||
protected array $locales = [];
|
protected array $locales = [];
|
||||||
|
protected array $defaultSort = [];
|
||||||
protected ?string $defaultLocale = null;
|
protected ?string $defaultLocale = null;
|
||||||
|
|
||||||
protected static $self;
|
protected static $self;
|
||||||
|
@ -225,4 +228,21 @@ class CrudConfiguration
|
||||||
{
|
{
|
||||||
return !empty($this->locales);
|
return !empty($this->locales);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -- */
|
||||||
|
|
||||||
|
public function setDefaultSort(string $context, string $label, string $direction = 'asc'): self
|
||||||
|
{
|
||||||
|
$this->defaultSort[$context] = [
|
||||||
|
'label' => $label,
|
||||||
|
'direction' => $direction,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaultSort(string $context)
|
||||||
|
{
|
||||||
|
return $this->defaultSort[$context] ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue