Skip to content
Snippets Groups Projects
Commit b83d9141 authored by Erik Seifert's avatar Erik Seifert
Browse files

Fix: add sort function for dashboards

parent c7120054
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,9 @@ dashboards.dashboard.*:
frontend:
type: boolean
label: 'Frontend'
weight:
type: integer
label: 'Weight'
sections:
type: sequence
sequence:
......
......@@ -65,7 +65,11 @@ function dashboards_toolbar() {
$entityTypeManager = \Drupal::entityTypeManager();
$boards = $entityTypeManager->getStorage('dashboard')->loadMultiple();
/**
* @var \Drupal\dashboards\Entity\DashboardStorage
*/
$storage = $entityTypeManager->getStorage('dashboard');
$boards = $storage->loadMultipleOrderedByWeight();
foreach ($boards as $key => $board) {
if (!$board->access('view', \Drupal::currentUser())) {
unset($boards[$key]);
......
......@@ -46,7 +46,8 @@ use Drupal\layout_builder\SectionStorage\SectionStorageTrait;
* },
* entity_keys = {
* "id" = "id",
* "label" = "admin_label"
* "label" = "admin_label",
* "weight" = "weight"
* },
* admin_permission = "administer dashboards",
* config_export = {
......@@ -55,7 +56,7 @@ use Drupal\layout_builder\SectionStorage\SectionStorageTrait;
* "category",
* "sections",
* "frontend",
* "overridable",
* "weight",
* }
* )
*
......@@ -102,11 +103,11 @@ class Dashboard extends ConfigEntityBase implements SectionListInterface {
public $sections = [];
/**
* Is overridable.
* Weight.
*
* @var bool
* @var int
*/
public $overridable = TRUE;
public $weight = 0;
/**
* Is overriden.
......@@ -171,16 +172,6 @@ class Dashboard extends ConfigEntityBase implements SectionListInterface {
}
}
/**
* Is this dashboard overridable.
*
* @return bool
* Return true if is overridable.
*/
public function isOverridable() {
return $this->overridable;
}
/**
* Check if is overriden.
*
......
......@@ -2,23 +2,39 @@
namespace Drupal\dashboards\Entity;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
/**
* Class DashboardListBuilder.
*
* @package Drupal\dashboards\Entity
*/
class DashboardListBuilder extends EntityListBuilder {
class DashboardListBuilder extends DraggableListBuilder {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dashboards';
}
/**
* {@inheritdoc}
*/
public function getOperations(EntityInterface $entity) {
$operations = [
'view' => [
'title' => new TranslatableMarkup('View'),
'weight' => 1,
'url' => Url::fromRoute(
'entity.dashboard.canonical', [
'dashboard' => $entity->id(),
]
),
],
'layout' => [
'title' => new TranslatableMarkup('Manage Layout'),
'weight' => 1,
......@@ -49,8 +65,8 @@ class DashboardListBuilder extends EntityListBuilder {
*/
public function buildRow(EntityInterface $entity) {
$row = [];
$row['label'] = $entity->toLink($entity->label());
$row['category'] = $entity->category;
$row['label'] = $entity->label();
$row['category']['#markup'] = $entity->category;
return $row + parent::buildRow($entity);
}
......
......@@ -13,6 +13,17 @@ use Drupal\layout_builder\Section;
*/
class DashboardStorage extends ConfigEntityStorage {
/**
* {@inheritdoc}
*/
public function loadMultipleOrderedByWeight(?array $ids = NULL) {
$entites = parent::loadMultiple($ids);
usort($entites, function ($a, $b) {
return $a->get('weight') <=> $b->get('weight');
});
return $entites;
}
/**
* {@inheritdoc}
*/
......
......@@ -51,11 +51,12 @@ class DashboardForm extends EntityForm {
'#default_value' => $entity->frontend,
];
$form['overridable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Overridable.'),
'#default_value' => $entity->overridable,
$form['weight'] = [
'#type' => 'number',
'#title' => $this->t('Weight.'),
'#default_value' => $entity->weight,
];
return $form;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment