From 8e801c68295644a20967598e201cc6924ad12a53 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sun, 30 Aug 2020 11:24:12 +0200 Subject: [PATCH] added support for ordering meta fields (#1940) --- src/Entity/MetaTableTypeInterface.php | 15 +++++++++++++++ src/Entity/MetaTableTypeTrait.php | 17 +++++++++++++++++ templates/activity/details.html.twig | 2 +- templates/activity/edit.html.twig | 4 +++- templates/customer/details.html.twig | 2 +- templates/customer/edit.html.twig | 4 +++- templates/project/details.html.twig | 2 +- templates/project/edit.html.twig | 4 +++- tests/Entity/AbstractMetaEntityTest.php | 8 +++++++- 9 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/Entity/MetaTableTypeInterface.php b/src/Entity/MetaTableTypeInterface.php index 9b7bf9d2..dc7c62f3 100644 --- a/src/Entity/MetaTableTypeInterface.php +++ b/src/Entity/MetaTableTypeInterface.php @@ -163,4 +163,19 @@ interface MetaTableTypeInterface * @return array */ public function getOptions(): array; + + /** + * Sets the weight order. + * + * @param int $order + * @return MetaTableTypeInterface + */ + public function setOrder(int $order): MetaTableTypeInterface; + + /** + * Returns the weight order. + * + * @return int + */ + public function getOrder(): int; } diff --git a/src/Entity/MetaTableTypeTrait.php b/src/Entity/MetaTableTypeTrait.php index 803e8a10..5562f86b 100644 --- a/src/Entity/MetaTableTypeTrait.php +++ b/src/Entity/MetaTableTypeTrait.php @@ -89,6 +89,10 @@ trait MetaTableTypeTrait * @var array */ private $options = []; + /** + * @var int + */ + private $order = 0; public function getName(): ?string { @@ -216,6 +220,7 @@ trait MetaTableTypeTrait ->setIsVisible($meta->isVisible()) ->setLabel($meta->getLabel()) ->setOptions($meta->getOptions()) + ->setOrder($meta->getOrder()) ; return $this; @@ -249,6 +254,18 @@ trait MetaTableTypeTrait return $this->options; } + public function getOrder(): int + { + return $this->order; + } + + public function setOrder(int $order): MetaTableTypeInterface + { + $this->order = $order; + + return $this; + } + public function __clone() { if ($this->id) { diff --git a/templates/activity/details.html.twig b/templates/activity/details.html.twig index 5766a5d3..27a92187 100644 --- a/templates/activity/details.html.twig +++ b/templates/activity/details.html.twig @@ -67,7 +67,7 @@ {% endif %} - {% for metaField in activity.visibleMetaFields %} + {% for metaField in activity.visibleMetaFields|sort((a, b) => a.order <=> b.order) %} {{ metaField.label|trans }} {{ widgets.form_type_value(metaField.type, metaField.value, activity) }} diff --git a/templates/activity/edit.html.twig b/templates/activity/edit.html.twig index 8ac42476..05191580 100644 --- a/templates/activity/edit.html.twig +++ b/templates/activity/edit.html.twig @@ -36,7 +36,9 @@ {% endif %} {{ form_row(form.visible) }} {% if form.metaFields is defined and form.metaFields is not empty %} - {{ form_row(form.metaFields) }} + {% for meta in form.metaFields|sort((a, b) => a.vars.data.order <=> b.vars.data.order) %} + {{ form_row(meta) }} + {% endfor %} {% endif %} {% if form.create_more is defined and app.request.xmlHttpRequest %}