3

I have system.xml with some fields:

<field id="image_width" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Image width</label>
</field>
<field id="image_height" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Image height</label>
</field>
<field id="placeholder_image" translate="label comment" type="image" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Image placeholder</label>
    <comment>Allowed file types:PNG, GIF, JPG, JPEG, SVG.</comment>
    <backend_model>MyNamespace\MyModule\Model\Config\Backend\Image\Placeholder</backend_model>
    <base_url type="media" scope_info="1">module_folder</base_url>
</field>

And i set default values for them in config.xml:

<image_width>100</image_width>
<image_height>100</image_height>
<placeholder_image>placeholder.gif</placeholder_image>

The problem is in placeholder_image field. My placeholder image lies in app/code/MyNamespace/MyModule/view/frontend/web/images/placeholder.gif and Magento 2 looks for it in pub/media/module_folder/placeholder.gif. How can i tell magento to copy it from my folder to pub/media?

1 Answer 1

2

I assume you have this code in one of your custom extensions.
You can use the Setup/InstallData.php or Setup/UpgradeData.php files that run when you install or upgrade the module and place an image inside the folder you need.

3
  • OP wants to set default values via module configxml
    – MagePsycho
    Jan 21, 2016 at 9:19
  • @MagePsycho. Yep. And this would work. Set the default value in config.xml then use the install/upgrade scripts to place that specific image into the desired folder.
    – Marius
    Jan 21, 2016 at 9:22
  • I think this is the only solution for now, so i accept it, but it would be great to have possibility to use something like <placeholder_image>Namespace_ModuleName::placeholder.gif</placeholder_image> in config.xml. Jan 28, 2016 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.