verbb / postie

A Craft Commerce shipping calculator plugin.
Other
12 stars 18 forks source link

SVG File could not be located solution #13

Closed keyurshah closed 4 years ago

keyurshah commented 4 years ago

Description

When creating a custom provider, I got the error below (with craftimport being the name of my project and local being the name of my provider.

This is due to the svg file for the custom provider not being in the verbb/postie resources folder.

Invalid Argument – yii\base\InvalidArgumentException
The file or directory to be published does not exist: D:\myfiles\laragon\www\craftimport\vendor/verbb/postie/src/resources/dist/img/local.svg

I was able to fix it by

1) adding this function to my provider file:

    public function getIconUrl()
    {
        $handle = strtolower($this->displayName());

        return Craft::$app->assetManager->getPublishedUrl('@pluginnamespace/pluginname/resources/dist/img/' . $handle . '.svg', true);
    }

replace @pluginnamespace/pluginname with your plugin namespace and path as described here under Extension Alias

2) adding an svg to my plugin directory src/resources/dist/img

Maybe mentioning this function in the docs would help, or if there's a different way of avoiding the error.

engram-design commented 4 years ago

Fixed in 2.1.0. Also updated the docs to reflect this example.