1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Calling functions inside Custom.php helper file

Discussion in 'Community' started by bggann, Jan 21, 2021.

  1. bggann

    bggann Member

    Level: Community
    Fabrik has the ability to load a custom helper file - as an alternative to using "require" or "require_once" in calcs.
    If you put a file called Custom.php in /libraries/fabrik/fabrik/helpers and then call
    FabrikCustom::doMyThing() in your code Fabrik will look in custom.php for the function doMyThing() and execute it. (there is an example file in there called CustomSample.php)

    My challenge is this.
    I call a function inside Custom.php and that function calls another function in Custom.php.
    It does not seem to work - it can't find the 2nd function. Is there a way to do that?

    Example (silly example code)

    My calc element is
    $parameter = '{placeholder}';
    $answer = FabrikCustom::doThingOne($parameter);
    return $answer;

    In custom.php are the two functions (this is not the full custom.php)
    public static function doThingOne($parameter) {
    $example = $parameter * 2;
    $new_answer = FabrikCustom::doThingTwo($example);
    return $new_answer;​

    public static function doThingTwo($example) {
    $stuff_I_did = $example * 2;
    return $stuff_I_did;​
    What I want to happen is
    -> The calc element calle doThingOne()
    -> doThingOne() calls doThingTwo()
    -> doThingTwo() returns an answer to doThingOne
    -> doThingOne() returns an answer to the calc
    -> The calc returns to the form.

    What does happen
    -> doThingOne() hangs with a spinner on the call to doThingTwo()

    It appears that doThingTwo() is not defined in the context of doThingOne()

    Any way around this?
  2. achartier

    achartier Active Member

    Level: Community
    It looks like you have a defined class called FabrikCustom inside this file? If so you could try self::doThingTwo($example). Without seeing the entire file it is hard to be sure.
  3. bggann

    bggann Member

    Level: Community
    Yes - that is correct self:: solved the problem. Thanks.
  4. achartier

    achartier Active Member

    Level: Community
    Glad it worked for you and thank you for coming back and confirming the solution.
  5. bggann

    bggann Member

    Level: Community
    This is the first time I've used a helper like this. I'm going to work on the wiki page - this is very useful if you have a complex form with lots of calcs or things like that.

Share This Page