Skip to content

Commit ec2d983

Browse files
committed
[ticket/15328] Disable checkbox if notification method isn't supported
PHPBB3-15328
1 parent 1e605ef commit ec2d983

6 files changed

Lines changed: 36 additions & 11 deletions

File tree

phpBB/includes/ucp/ucp_notifications.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ public function output_notification_types($subscriptions, \phpbb\notification\ma
180180
'GROUP_NAME' => $user->lang($group),
181181
));
182182

183-
foreach ($subscription_types as $type => $data)
183+
foreach ($subscription_types as $type => $type_data)
184184
{
185185
$template->assign_block_vars($block, array(
186186
'TYPE' => $type,
187187

188-
'NAME' => $user->lang($data['lang']),
189-
'EXPLAIN' => (isset($user->lang[$data['lang'] . '_EXPLAIN'])) ? $user->lang($data['lang'] . '_EXPLAIN') : '',
188+
'NAME' => $user->lang($type_data['lang']),
189+
'EXPLAIN' => (isset($user->lang[$type_data['lang'] . '_EXPLAIN'])) ? $user->lang($type_data['lang'] . '_EXPLAIN') : '',
190190
));
191191

192192
foreach ($notification_methods as $method => $method_data)
@@ -196,6 +196,8 @@ public function output_notification_types($subscriptions, \phpbb\notification\ma
196196

197197
'NAME' => $user->lang($method_data['lang']),
198198

199+
'AVAILABLE' => $method_data['method']->is_available($type_data['type']),
200+
199201
'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) ? true : false,
200202
));
201203
}

phpBB/phpbb/notification/manager.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,10 @@ public function get_subscription_types()
475475
if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available())
476476
{
477477
$options = array_merge(array(
478-
'id' => $type->get_type(),
479-
'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()),
480-
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',
478+
'type' => $type,
479+
'id' => $type->get_type(),
480+
'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()),
481+
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',
481482
), (($type::$notification_option !== false) ? $type::$notification_option : array()));
482483

483484
$this->subscription_types[$options['group']][$options['id']] = $options;
@@ -509,6 +510,7 @@ public function get_subscription_methods()
509510
foreach ($this->get_available_subscription_methods() as $method_name => $method)
510511
{
511512
$subscription_methods[$method_name] = array(
513+
'method' => $method,
512514
'id' => $method->get_type(),
513515
'lang' => str_replace('.', '_', strtoupper($method->get_type())),
514516
);

phpBB/phpbb/notification/method/email.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ public function get_type()
5656
/**
5757
* Is this method available for the user?
5858
* This is checked on the notifications options
59+
*
60+
* @param \phpbb\notification\type\type_interface $notification_type An optional instance of a notification type. If provided, this
61+
* method additionally checks if the type provides an email template.
62+
* @return bool
5963
*/
60-
public function is_available()
64+
public function is_available(\phpbb\notification\type\type_interface $notification_type = null)
6165
{
62-
return $this->config['email_enable'] && $this->user->data['user_email'];
66+
return parent::is_available($notification_type) && $this->config['email_enable'] && $this->user->data['user_email'];
6367
}
6468

6569
/**

phpBB/phpbb/notification/method/jabber.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ public function get_type()
5656
/**
5757
* Is this method available for the user?
5858
* This is checked on the notifications options
59+
*
60+
* @param \phpbb\notification\type\type_interface $notification_type An optional instance of a notification type. If provided, this
61+
* method additionally checks if the type provides an email template.
62+
* @return bool
5963
*/
60-
public function is_available()
64+
public function is_available(\phpbb\notification\type\type_interface $notification_type = null)
6165
{
62-
return ($this->global_available() && $this->user->data['user_jabber']);
66+
return parent::is_available($notification_type) && $this->global_available() && $this->user->data['user_jabber'];
6367
}
6468

6569
/**

phpBB/phpbb/notification/method/messenger_base.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ public function __construct(\phpbb\user_loader $user_loader, $phpbb_root_path, $
4242
$this->php_ext = $php_ext;
4343
}
4444

45+
/**
46+
* Is this method available for the user?
47+
* This is checked on the notifications options
48+
*
49+
* @param \phpbb\notification\type\type_interface $notification_type An optional instance of a notification type. This method returns false
50+
* only if the type is provided and if it doesn't provide an email template.
51+
* @return bool
52+
*/
53+
public function is_available(\phpbb\notification\type\type_interface $notification_type = null)
54+
{
55+
return $notification_type === null || $notification_type->get_email_template() !== false;
56+
}
57+
4558
/**
4659
* Notify using phpBB messenger
4760
*

phpBB/styles/prosilver/template/ucp_notifications.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2>{TITLE}</h2>
3131
<!-- IF notification_types.EXPLAIN --><br />&nbsp; &nbsp;{notification_types.EXPLAIN}<!-- ENDIF -->
3232
</td>
3333
<!-- BEGIN notification_methods -->
34-
<td class="mark"><input type="checkbox" name="{notification_types.TYPE}_{notification_methods.METHOD}"<!-- IF notification_methods.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /></td>
34+
<td class="mark"><input type="checkbox" name="{notification_types.TYPE}_{notification_types.notification_methods.METHOD}"<!-- IF notification_types.notification_methods.AVAILABLE and notification_types.notification_methods.SUBSCRIBED --> checked="checked"<!-- ENDIF --><!-- IF not notification_types.notification_methods.AVAILABLE --> disabled="disabled"<!-- ENDIF --> /></td>
3535
<!-- END notification_methods -->
3636
</tr>
3737
<!-- ENDIF -->

0 commit comments

Comments
 (0)