Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the posibility to also use transistent and toast notifications #19

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AdminNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setNotificationV3()
$notification = new Notification($settings->message->getValue());
$notification->title = $settings->messageTitle->getValue();
$notification->context = $settings->context->getValue();
$notification->type = Notification::TYPE_PERSISTENT;
$notification->type = $settings->type->getValue();
//$notification->priority = Notification::PRIORITY_MAX;

//echo "NOTIFY";
Expand Down
23 changes: 23 additions & 0 deletions SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
/** @var Setting */
public $message;

/** @var Setting */
public $type;

protected function init()
{

Expand All @@ -46,6 +49,8 @@ protected function init()
$this->messageTitle = $this->createTitleSetting();

$this->message = $this->createMessageSetting();

$this->type = $this->createTypeSetting();
}

private function createEnabledSetting()
Expand Down Expand Up @@ -103,6 +108,24 @@ private function createMessageSetting()
});
}

private function createTypeSetting()
{
return $this->makeSetting(
'type',
$default = "persistent",
FieldConfig::TYPE_STRING,
function (FieldConfig $field) {
$field->title = $this->t('TypeSettingTitle');
$field->condition = 'enabled';
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
$field->description = $this->t('TypeSettingDescription');
$field->availableValues = array(Notification::TYPE_PERSISTENT => Notification::TYPE_PERSISTENT,
Notification::TYPE_TRANSIENT => Notification::TYPE_TRANSIENT,
Notification::TYPE_TOAST => Notification::TYPE_TOAST);
}
);
}

private function t($translate_token)
{
return Piwik::translate("AdminNotification_" . $translate_token);
Expand Down
5 changes: 4 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"ContextSettingTitle": "Context",
"ContextSettingDescription": "Sets what type of message should be displayed (affects color).",
"TitleSettingTitle": "Title",
"TitleSettingDescription": "Sets the title of the message. This will be dislayed in bold with the message."
"TitleSettingDescription": "Sets the title of the message. This will be dislayed in bold with the message.",
"TypeSettingTitle": "Type",
"TypeSettingDescription": "Persistent (display until user closes the notification), Transient (displays once, disappear on page reload) or Toast (displayed for a few seconds, and the fades out)"

}
}