From 6560b1e82d4afd33e389a2e3d7c9a8a1144cb481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org> Date: Thu, 18 Jun 2020 10:05:09 +0200 Subject: [PATCH] :sparkles: feat(core) Allow passing an error object to msg_dialog::display issue #6071 --- include/class_msg_dialog.inc | 8 ++++++-- include/errors/class_SimplePluginLdapError.inc | 2 +- include/simpleplugin/attributes/class_SetAttribute.inc | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/class_msg_dialog.inc b/include/class_msg_dialog.inc index c06cdd6d6..a160224eb 100644 --- a/include/class_msg_dialog.inc +++ b/include/class_msg_dialog.inc @@ -120,7 +120,7 @@ class msg_dialog /*! * \brief Display a message dialog * - * \param string $title The title of the message dialog + * \param string|object $title The title of the message dialog, or the error object * * \param string $message The message of the message dialog * @@ -128,8 +128,12 @@ class msg_dialog * * \param array $trace The trace from where the message was built */ - public static function display (string $title, string $message, int $type = INFO_DIALOG, array $trace = []) + public static function display ($title, string $message, int $type = INFO_DIALOG, array $trace = []) { + if ($title instanceof FusionDirectoryError) { + static::display(...$title->computeMsgDialogParameters()); + return; + } $dialog = new msg_dialog($title, $message, $type, $trace); $dialog->show(); } diff --git a/include/errors/class_SimplePluginLdapError.inc b/include/errors/class_SimplePluginLdapError.inc index f66b040d4..1c7eb5ced 100644 --- a/include/errors/class_SimplePluginLdapError.inc +++ b/include/errors/class_SimplePluginLdapError.inc @@ -98,6 +98,6 @@ class SimplePluginLdapError extends SimplePluginError ] ); - return [_('Error'), $html, ERROR_DIALOG, $trace]; + return [_('LDAP error'), $html, LDAP_ERROR, $trace]; } } diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc index 824f4b4b4..f76266904 100644 --- a/include/simpleplugin/attributes/class_SetAttribute.inc +++ b/include/simpleplugin/attributes/class_SetAttribute.inc @@ -666,7 +666,11 @@ class OrderedArrayAttribute extends SetAttribute $this->attribute->loadPostValue(); $this->attribute->applyPostValue(); if ($error = $this->attribute->check()) { - msg_dialog::display(sprintf(_('Invalid value for %s'), $this->getLabel()), $error); + if (is_string($error)) { + msg_dialog::display(sprintf(_('Invalid value for %s'), $this->getLabel()), $error); + } else { + msg_dialog::display($error); + } } else { $this->addPostValue($this->attribute->getValue()); } -- GitLab