From b436a0641dc3218e2da6de90de815da3e9ba2516 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 5 Aug 2020 16:31:39 +0000 Subject: [PATCH] [CONTROLLER][UI] Add notification settings form --- src/Controller/UserPanel.php | 16 ++++++----- templates/settings/notifications.html.twig | 32 ++++++++++++++-------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/Controller/UserPanel.php b/src/Controller/UserPanel.php index 77a1557cdc..607e35e3ec 100644 --- a/src/Controller/UserPanel.php +++ b/src/Controller/UserPanel.php @@ -110,27 +110,29 @@ class UserPanel extends AbstractController { $schema = DB::getConnection()->getSchemaManager(); $platform = $schema->getDatabasePlatform(); - $columns = Common::array_remove_keys($schema->listTableColumns('user_notification_prefs'), ['user_id', 'transport', 'created', 'modified']); + $columns = Common::arrayRemoveKeys($schema->listTableColumns('user_notification_prefs'), ['user_id', 'transport', 'created', 'modified']); $form_defs = ['placeholder' => []]; foreach ($columns as $name => $col) { - $val = $col->getType()->convertToPHPValue($col->getDefault(), $platform); - switch ($col->getType()) { + $type = $col->getType(); + $val = $type->convertToPHPValue($col->getDefault(), $platform); + $type_str = lcfirst(substr((string) $type, 1)); + $label = str_replace('_', ' ', ucfirst($name)); + switch ($type_str) { case Types::BOOLEAN: - $form_defs['placeholder'][] = [$name, CheckboxType::class, ['data' => $val, 'label' => _m($col->getComment())]]; + $form_defs['placeholder'][] = [$name, CheckboxType::class, ['data' => $val, 'label' => $label, 'help' => _m($col->getComment())]]; break; case Types::INTEGER: if ($name == 'target_profile_id') { - $form_defs['placeholder'][] = ['target_profiles', TextType::class, ['data' => $val, 'label' => _m($col->getComment())], 'transformer' => ProfileArrayTransformer::class]; + $form_defs['placeholder'][] = ['target_profiles', TextType::class, ['data' => $val, 'label' => $label, 'help' => _m($col->getComment())], 'transformer' => ProfileArrayTransformer::class]; break; } - // fallthrough // no break default: throw new Exception("Structure of table user_notification_prefs changed in a way not accounted to in notification settings ({$name})", 500); } } - Event::handle('AddNotificationTransport', [&$form_defs]); + Event::handle('add_notification_transport', [&$form_defs]); unset($form_defs['placeholder']); $tabbed_forms = []; diff --git a/templates/settings/notifications.html.twig b/templates/settings/notifications.html.twig index c95f8f1295..71edf7370a 100644 --- a/templates/settings/notifications.html.twig +++ b/templates/settings/notifications.html.twig @@ -3,19 +3,29 @@ {% block title %}Notification Settings{% endblock %} {% block body %} +
+ {% block primary_nav %} + {{ parent() }} + {% endblock primary_nav %} -
- {% block primary_nav %} - {{ parent() }} - {% endblock primary_nav %} - - {% block form %} + {% block form %} +
+
    {% for transport, form in tabbed_forms %} -
    - {{ form(form) }} -
    +
  • + {{ transport }} +
  • {% endfor %} - {% endblock form %} -
+ +
+
+ {% for transport, form in tabbed_forms %} +
+ {{ form(form) }} +
+ {% endfor %} +
+ {% endblock form %} +
{% endblock body %}