I have created a field in system->config to save an attribute code which is already created.(For eg:color)

Based on that value, I need to get all the option values of that attribute.(ie ,In my admin form drop down, I need to display its option values as red,blue,green).

How it is possible ? Please help.

1 Answer 1


Add to the constructor in your class an instance of \Magento\Eav\Model\Config like this:

protected $eavConfig;
public function __construct(
    \Magento\Eav\Model\Config $eavConfig,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    $this->eavConfig = $eavConfig;
    $this->scopeConfig = $scopeConfig;

then you can use that in your class

$attribute_code_here = $this->scopeConfig->getValue('dev/debug/template_hints', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$attribute = $this->eavConfig->getAttribute('catalog_product', $attribute_code_here);
$options = $attribute->getSource()->getAllOptions();
  • @V.P, If my answer solve your issue then mark as accepted. So other user take benefits from this. Commented Dec 29, 2016 at 13:36
  • I also want to show product attribute label in custom grid instead of attribute value. Currently it showing attribute option value. please suggest Commented Aug 25, 2017 at 14:07
  • I want to display attribute options dropdown in admin form and grid, please help me
    – Ashna
    Commented Jul 23, 2018 at 8:04

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.