• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Q&A for 'Creating an Addon.' by Lawrence

dmnkhhn

Active member
#1
Lawrence, you are doing great work with your 'Creating an Addon' walkthrough.
I thought it would be good idea to have a place where users can ask questions about your code. :)

Please let me start with my first question:

In LimitSig -> ControllerPublic -> LimitSig.php you are creating a new function that has the same name as the original function.
The original function then gets overwritten by that new function but that means that we need to duplicate the original function first and copy it to LimitSig.php so that we don't loose the logic that is needed by the account. Without copying the existing code the function would not be complete.

What happens if we have two different add-ons that both replace the actionSignatur function?

Take this as an example:

Original:

PHP:
    public function actionSignature()     {
 $test = $this->getSomeStrangeVariable();
        return $test;
    }

Addon 1:
PHP:
    public function actionSignature()     {
 $test = $this->getSomeStrangeVariable();
        return strtoupper($test);
    }

Addon 2:
PHP:
    public function actionSignature()     {
 $test = $this->getSomeStrangeVariable();
        return md5($test);
    }
 

Jeremy

Well-known member
#2
You are able to do this:

PHP:
public function actionSignature()
{
      // Your Logic.
      parent::actionSignature();
      return 'something';
}
Without duplicating and/or losing functionality.
 

Lawrence

Well-known member
#4
When the guide is finished I'll be opening it up for discussion.

Thanks for starting this thread, :)

All we are adding is another check to see if a member can edit their signature, or not, with the function. If they can, show the editor, and if they cannot, spit out the error. The original actionSignature function is just a permission check that does the same thing, so any other Add-on that uses the function will be giving the same functionality as this Add-on does anyways.
 

dmnkhhn

Active member
#5
Something I've learned today from a co-worker and that's worth mentioning. :)

If the parent function contains a return, you can use that return value like so:
PHP:
$oldReturn = parent::actionSignature();
 

Lawrence

Well-known member
#6
Sorry for the delay, I needed to be away for this week, so I'm only on and off. I am working on the next part, however; and hopefully will have it up soon.