Asset Link - plugins across devices

@Symbioquine I finally made it to try out Asset Link for real.

I forked @Farmer-Ed’s bale inventory plugin to make a diesel fuel plugin.
I shows a button on equipment assets beeing members of a “vehicle” group.

So far so good.

I just added the plugin from Asset Link itself. I expected it to show up on other devices as well, but it did’nt.

Is it supposed to?
Should I use another approach?

2 Likes

Awesome to hear you’re playing around with Asset Link @pat! I’ll defer to @Symbioquine for the official answer, but I think I understand enough to give a basic explanation…

Asset link has a plugin system that can be “fed” from two sources:

  1. Plugins that are loaded directly into asset link via the plugin UI that it provides are only available on that individual device.
  2. Plugins that are loaded from the farmOS server that is hosting it are available to all devices.

My understanding is plugins can be “wrapped” in a farmOS module that is installed on the server, so it might just be a matter of wrapping your plugin in a module.

2 Likes

Exactly, #1 allows users to directly make and share small units of functionality (plugins) for Asset Link. There is a “share” function within the plugin management UI in Asset Link itself which can be used to download the plugin as a file.

That plugin file could be loaded on another device or by another user.

#2: Allows the farmOS admin to add a plugin to the set of plugins that all users/devices get from the farmOS server in one of two ways;

3 Likes

I like this system because it allows for experimentation in individual devices, and once that seems stable and shareable, it can be formally packaged and distributed to others as a module!

4 Likes

Those default plugins are internally modeled as Drupal config entities so they can be accessed/updated via PHP/json:api for advanced use-cases too.

4 Likes

Ah. That makes sense. Thanks

1 Like

Hmm… I can’t add plugin from the configuration page.
I got 404 error on a locally hosted plugin.
I also somehow got root:root permissions on the Asset Link module folder.

Can the plugin url be anything local or e.g. a github url?

Hmmm, without seeing what you did, I’d guess a problem with the URL or maybe the file just isn’t being served by your web server. Did you confirm that you can access the locally hosted plugin via your browser?

If you’re trying to get Asset Link to actually serve your plugin, it’s worth noting this excerpt from the docs;

Important: If the plugin is named “NameBobAssetActionProvider.alink.js”, then the id field of the config yml must be “NameBobAssetActionProvider” and the yml file itself must be named “farmos_asset_link.asset_link_default_plugin.NameBobAssetActionProvider.yml”. All three must match, otherwise the plugin cannot be served/loaded correctly by the Asset Link Drupal controller.

In other words Asset Link includes a bit of code to actually serve other farmOS modules’ plugin files, but because that could be a security risk (if it served other files by accident) it has very strict conditions about which files it serves.

Yes - with two caveats:

  1. If you’re just going to put in an arbitrary url, it needs to already be accessible by your browser.
    • Other than the special case described above where urls like https://my.farm/alink/plugins/~NameBobAssetActionProvider.alink.js get automatically served by Asset Link.
  2. If you put in a url under a different (sub)domain, then you need to ensure the plugin is served with the appropriate CORS headers such that it can be loaded from Asset Link.

Is that unexpected? I just checked my /opt/drupal/web/modules folder and all the modules have root:root ownership.

1 Like

Thanks. Not completely clear yet, but I managed for now.