Jump to content

[v5 REQUEST] Implement extension functions more consistently


Go to solution Solved by Daniel F,

Recommended Posts

Posted (edited)

Please keep the extension's behavior consistent across all the functions. Some extensions first check if the extension implements a certain function before calling it, while others expect the function to exist at all times and throw errors if they're missing.

 

For example, the core/ModeratorPermissions currently has 4 functions available (preSave, getPermissions, onChange, onDelete) but only preSave checks if the function is available before calling it:

/* Allow extensions an opportunity to inspect the values and make adjustments */
foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
	if( method_exists( $ext, 'preSave' ) )
	{
		$ext->preSave( $values );
	}
}

 

The other functions instead are called without any check:

foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE, 'core' ) as $k => $ext )
{
	foreach( $ext->getPermissions( array() ) as $name => $data )
	{
		// ...
	}
}

===

foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
	$ext->onChange( $current, $changed );
}

===

foreach ( \IPS\Application::allExtensions( 'core', 'ModeratorPermissions', FALSE ) as $k => $ext )
{
	$ext->onDelete( $current );
}

 

While I understand that getPermission() must be always implemented (the extension would have no meaning otherwise), the other 2 functions onChange() and onDelete() are completely optional and cause empty functions to be left around. For example, this code below comes from the Blog's extension:

	/**
	 * After change
	 *
	 * @param	array	$moderator	The moderator
	 * @param	array	$changed	Values that were changed
	 * @return	void
	 */
	public function onChange( $moderator, $changed )
	{
		
	}
	
	/**
	 * After delete
	 *
	 * @param	array	$moderator	The moderator
	 * @return	void
	 */
	public function onDelete( $moderator )
	{
		
	}
Edited by teraßyte
Posted (edited)

On another note, the preSave function is not even included in the file added by the developer center when you add the extension from ACP. That's another thing that should be double-checked: update example files with all available functions and clearly indicate which ones are required.

 

EDIT

Nevermind, I actually mixed up ModeratorPermissions with ContentModeratorPermissions (that doesn't support preSave). It's still something that should be double-checked for all extensions anyway.

Edited by teraßyte
  • Solution
Posted

Extensions will be easier to implement in v5 because there's now an abstract class with all mandatory abstract methods 🙂 

 

Quote

 

  • All extensions now have an abstract class that should be extended. Most of these can be found under \IPS\Extensions. The abstract class is typically the same name as the extension type (e.g. EditorLocations extend EditorLocationsAbstract). Verify that your extensions use the correct abstract class and that all your method signatures and properties are declared correctly.
  • Recently Browsing   0 members

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