I want to add image role in my custom page in admin side. There are four image role in core part . I want to add same as in my custom page.

How to add it in my custom page as mentioned in image

please help me.... enter image description here


You can add new image type using this code (from setup data script of your module):

namespace Vendor\Module\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
     * EAV setup factory
     * @var EavSetupFactory
    private $eavSetupFactory;

     * Init
     * @param EavSetupFactory $eavSetupFactory
    public function __construct(EavSetupFactory $eavSetupFactory)
        $this->eavSetupFactory = $eavSetupFactory;

     * {@inheritdoc}
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

                'type' => 'varchar',
                'label' => 'Image Attribute Name (Label)',
                'input' => 'media_image',
                'frontend' => 'Magento\Catalog\Model\Product\Attribute\Frontend\Image',
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'filterable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => true,
                'sort_order' => 10,
                'required' => false,

Replace attribute_image_code with code of your own attribute and do not forget to rename attribute label.

  • I want to add in phtml file...how to add it? – Rohan Hapani Jun 23 '17 at 12:27
  • 3
    I don't want to add new image type... i want to use image role which is already available in core – Rohan Hapani Jun 23 '17 at 12:28
  • Please, add code to clarify you question – Siarhey Uchukhlebau Jun 23 '17 at 12:29
  • @RohanHapani did you find a solution? This answer seems to just add a new EAV property and not update the Role list – Shawn Northrop Nov 27 '17 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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