Jump to content

Can't find custom addon


Spinbox
 Share

Recommended Posts

Hi @kongondo,

I have followed the guideline how to set up an addon for Padloper.

The file is located in /site/templates/padloper/addons/CSVImporter/CSVImporter.php with classname CSVImporter

It has the required methods. Any idea how to get this to be detected?

Link to comment
Share on other sites

  • 4 months later...

Can someone tell me where I'm going wrong. I'm a little lost with the MyAwesomeAddon documentation.

 

<?php 

namespace ProcessWire;

class TestAddon extends WireData implements PadloperAddons {

  /**
   * @var string
   */
  protected $renderViewURL;

  public function __construct() {
    $this->renderViewURL = 'go-cardless';
  }

  /**
   * Returns addon type.
   *
   * Must be one of Padloper pre-defined types.
   *
   * @return string
   */
  public function getType() {
    return 'custom';
  }

  /**
   * Returns addon class name.
   *
   * @return string
   */
  public function getClassName() {
    return "TestAddon";
  }

  /**
   * Returns user-friendly title of this addon.
   *
   * @return string
   */
  public function getTitle() {
    return "TestAddon Title";
  }

  /**
   * Returns short description of this addon.
   *
   * @return string
   */
  public function getDescription() {
    return "TestAddon description here.";
  }
}

 

Link to comment
Share on other sites

/**
   * Returns addon type.
   *
   * Must be one of Padloper pre-defined types.
   *
   * @return string
   */
  public function getType() {
    return 'custom';
  }

If I return 'payment' it shows in the addons table, but I was following the docs which says to return 'custom'

Link to comment
Share on other sites

Morning @alexm,

Apologies for the confusing docs (and perhaps naming issues). All non-payment addons must return 'custom' for getType(). Payment addons, even custom ones, are not defined as 'custom' addons. They are defined as payment addons and must return 'payment' for getType().

So, the idea of 'custom' does not mean 'third-party' or 'non-core'. Instead, it means the addon does something that is not necessarily a feature of Padloper, i.e. it does something custom. Since 'payment' is something that is a feature of Padloper, even third-party payment modules are not considered 'custom' since their function/role is to do something that is part of the core function of Padloper, i.e. payments.

Hope this makes sense. Will revise docs.

  • Like 1
Link to comment
Share on other sites

Morning @kongondo, but ignoring me setting the renderViewURL property to 'go-cardless', say I want to make, for the sake of argument, a discount code addon - what would I set the returned value of getType() to?
'custom' doesn't work for me and if I set it to that, nothing shows in the addons table

Happy Sunday mate

Link to comment
Share on other sites

5 hours ago, alexm said:

say I want to make, for the sake of argument, a discount code addon - what would I set the returned value of getType() to?

Hey @alexm, the value of that would have to be 'custom'. All non-payment addons must be of type 'custom'.

4 hours ago, alexm said:

Got it! Needs to be public property

Yes. Sorry about that. I need to state that in the docs. Does this mean your question above about 'getType()' is now sorted? Thanks.

  • Like 1
Link to comment
Share on other sites

18 hours ago, kongondo said:

Yes. Sorry about that. I need to state that in the docs. Does this mean your question above about 'getType()' is now sorted? Thanks.

Correctamundo. This resolves this matter thank you sir

  • Like 1
Link to comment
Share on other sites

Good evening @kongondo, just a quick one (hopefully). Sorry in advance, I'm not much cop with module development etc.
I'm just wondering how I access the addon page and 'padloper_settings' field name from the TestAddon class.

I note the setAddonPage() method in the custom addon docs but not sure/understanding entirely it's purpose or if this is used to retrieve them?

But effectively I've created a method saveConfigurations() which gets passed the fields array and JSON encoded ready to save to the 'padloper_settings' field. Now I just need to figure accessing the page object and field name in the right manner rather than hard coding.

Thank you in advance for any assistance as always.

  • Like 1
Link to comment
Share on other sites

Hi @alexm,

21 hours ago, alexm said:

if this is used to retrieve them?

Exactly. An example:

<?php

namespace ProcessWire;


public function setAddonPage(Page $page, string $addonSettingsFieldName) {
  // here we assign these variables to class properties for convenience
  // you don't have to do that
  // you can use $page directly to get your settings using 'addonSettingsFieldName' 
  $this->addonPage = $page;
  $this->addonSettingsFieldName = $addonSettingsFieldName;

  // --------
  // EXAMPLE
  $addonSettingsJSON = $page->get($addonSettingsFieldName);
  bd($addonSettingsJSON, __METHOD__ . ': $addonSettingsJSON at line #' . __LINE__);
  if(!empty($addonSettingsJSON)){
    $addonSettingsArray = json_decode($addonSettingsJSON,true);
    // do something with $addonSettingsArray
  }
}

I thought I had a hello world addon example in the demo projects. Looks like I don't. I'll add that to my TODO.

 

  • Like 1
Link to comment
Share on other sites

Long and short of this is thank you @kongondo for helping me to rectify the issue with my custom addon (which I will happily share) once done. It was due to me not correctly setting up the necessary methods and properties before installation, so one I knew that my custom addon's main class file was correct, per @kongondo's advice, I simply de-activated and re-activated the module and I am able to access the addone page and fieldname as expected. Big thank you as always dude!

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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