Jump to content

BUG: 4.7.7 Notifications configurationOptions


Go to solution Solved by Daniel F,

Recommended Posts

Posted

Found a small bug which only seems to show when I have Whoops enabled.

This happened when viewing a member's profile in the ACP and an applications Notification configurationOptions function does NOT explicitly set a return.

Such as:

	public static function configurationOptions( \IPS\Member $member = NULL )
	{
		if ( $member === NULL or $member->modPermission( 'can_view_hidden_content' ) )
		{
			return [
				'my_notification' => [
					'type'              => 'standard',
					'notificationTypes' => ['my_notifiction'],
					'title'             => 'notifications__my_notification',
					'showTitle'         => FALSE,
					'description'       => 'notifications__my_notification_desc',
					'default'           => ['inline'],
					'disabled'          => ['email', 'push']
				]
			];
		}
	}

Could contain: Text

Could contain: Page, Text, File

Posted

What application is that code from? It's not from the default IPS code at least.

 

The problem is that the return array() code is inside the IF check, if the check fails nothing is returned. Adding a simple return at the end of the function is enough:

	public static function configurationOptions( \IPS\Member $member = NULL )
	{
		if ( $member === NULL or $member->modPermission( 'can_view_hidden_content' ) )
		{
			return [
				'my_notification' => [
					'type'              => 'standard',
					'notificationTypes' => ['my_notifiction'],
					'title'             => 'notifications__my_notification',
					'showTitle'         => FALSE,
					'description'       => 'notifications__my_notification_desc',
					'default'           => ['inline'],
					'disabled'          => ['email', 'push']
				]
			];
		}
		
		return array();
	}

 

Posted
1 hour ago, teraßyte said:

What application is that code from? It's not from the default IPS code at least.

 

The problem is that the return array() code is inside the IF check, if the check fails nothing is returned. Adding a simple return at the end of the function is enough:

	public static function configurationOptions( \IPS\Member $member = NULL )
	{
		if ( $member === NULL or $member->modPermission( 'can_view_hidden_content' ) )
		{
			return [
				'my_notification' => [
					'type'              => 'standard',
					'notificationTypes' => ['my_notifiction'],
					'title'             => 'notifications__my_notification',
					'showTitle'         => FALSE,
					'description'       => 'notifications__my_notification_desc',
					'default'           => ['inline'],
					'disabled'          => ['email', 'push']
				]
			];
		}
		
		return array();
	}

 

It's just an example which will trigger the Warning in Whoops. 🙂

  • Solution
Posted

The method should return an array (mentioned by phpdoc)

Unfortunately, there were no return types when IPS 4 was created, but they're now, so I guess the best thing to do here is to enforce it

Dr Evil GIF

 

Seems much more straightforward than including just another IMO unnecesary check for the methods return value.

Posted
18 minutes ago, Daniel F said:

The method should return an array (mentioned by phpdoc)

Unfortunately, there were no return types when IPS 4 was created, but they're now, so I guess the best thing to do here is to enforce it

Dr Evil GIF

 

Seems much more straightforward than including just another IMO unnecesary check for the methods return value.

Developers don't always do what is in the manual. 🤪

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...