Magento 2 Load database value to custom field in product attributeMagento2 How to query value in catalog_eav_attribute?main.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?How to save custom product tab checkbox value in database using Magento 2I have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listMagento 2.2.5 : Add custom field in product attribute add formWidget/block code in product custom attribute not rendering at front-end magento 2.2.5I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.6 : Add custom field in product attribute add form - Is not render the database value on editHow to create an extra field in attribute information

Linux ext4 restore file and directory access rights after bad backup/restore

Do gauntlets count as armor?

What's the physical meaning of the statement that "photons don't have positions"?

What's the largest an Earth-like planet can be and support Earth's biosphere?

Why teach C using scanf without talking about command line arguments?

Inside Out and Back to Front

Why don't humans perceive sound waves as twice the frequency they are?

Three Subway Escalators

Masyu-making game

Are there any satellites in geosynchronous but not geostationary orbits?

Does the Bracer of Flying Daggers really let a thief make 4 attacks per round?

"This used to be my phone number"

How does the Gameboy's memory bank switching work?

Project Euler # 25 The 1000 digit Fibonacci index

How to not confuse readers with simultaneous events?

Extract the attribute names from a large number of Shapefiles

Do higher dimensions have axes?

Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?

Counting multiples of 3 up to a given number

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?

Discontinuous Tube visualization

Why is this guy handcuffed censored?

You have no, but can try for yes

Do Indians need sepearte Hong Kong visa if we already have Chinese visa



Magento 2 Load database value to custom field in product attribute


Magento2 How to query value in catalog_eav_attribute?main.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?How to save custom product tab checkbox value in database using Magento 2I have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listMagento 2.2.5 : Add custom field in product attribute add formWidget/block code in product custom attribute not rendering at front-end magento 2.2.5I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.6 : Add custom field in product attribute add form - Is not render the database value on editHow to create an extra field in attribute information






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am adding a custom field to product attributes with a plugin providing the adminhtml display.



I have it visible in Store -> Attributes -> Product -> Edit attribute and it works okay to save, but when editing a product attribute the stored value is not loaded. The value is initially correctly stored in the database, subsequent visits to edit do not load the saved value from the database.



How can I have this yesno successfully pull the stored value when an admin is editing the attribute? I'm not sure why the value isn't being pulled with the current one being selected. This is Magento 2.2.7




CompanyNameModuleNameSetupUpgradeSchema.php




<?php
namespace CompanyNameModuleNameSetup;
use MagentoFrameworkSetupUpgradeSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
if (version_compare($context->getVersion(), '1.0.1') < 0)
$setup->startSetup();
$setup->getConnection()->addColumn(
$setup->getTable('catalog_eav_attribute'),
'my_custom_field',
['type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
'length' => '1',
'nullable' => false,
'unsigned' => true,
'default' => '0',
'comment' => 'This is a custom field']);
$setup->endSetup();




CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




<?php
namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;

class Front


/**
* @var Yesno
*/
protected $_yesNo;

/**
* @param MagentoConfigModelConfigSourceYesno $yesNo
*/
public function __construct(
MagentoConfigModelConfigSourceYesno $yesNo
)
$this->_yesNo = $yesNo;


/**
* Get form HTML
*
* @return string
*/
public function aroundGetFormHtml(
MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
Closure $proceed
)


$yesnoSource = $this->_yesNo->toOptionArray();
$form = $subject->getForm();
$fieldset = $form->getElement('front_fieldset');
$fieldset->addField(
'my_custom_field',
'select',
[
'name' => 'my_custom_field',
'label' => __('Label for my custom field'),
'title' => __('Title for my custom field'),
'note' => __('Note for my custom field.'),
'values' => $yesnoSource,
]
);
return $proceed();





CompanyName/ModuleName/etc/adminhtml/di.xml




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront">
<plugin name="companyname_attribute_edit_form" type="CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront" sortOrder="1"/>
</type>
</config>


enter image description here










share|improve this question






























    0















    I am adding a custom field to product attributes with a plugin providing the adminhtml display.



    I have it visible in Store -> Attributes -> Product -> Edit attribute and it works okay to save, but when editing a product attribute the stored value is not loaded. The value is initially correctly stored in the database, subsequent visits to edit do not load the saved value from the database.



    How can I have this yesno successfully pull the stored value when an admin is editing the attribute? I'm not sure why the value isn't being pulled with the current one being selected. This is Magento 2.2.7




    CompanyNameModuleNameSetupUpgradeSchema.php




    <?php
    namespace CompanyNameModuleNameSetup;
    use MagentoFrameworkSetupUpgradeSchemaInterface;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupSchemaSetupInterface;
    class UpgradeSchema implements UpgradeSchemaInterface
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    if (version_compare($context->getVersion(), '1.0.1') < 0)
    $setup->startSetup();
    $setup->getConnection()->addColumn(
    $setup->getTable('catalog_eav_attribute'),
    'my_custom_field',
    ['type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
    'length' => '1',
    'nullable' => false,
    'unsigned' => true,
    'default' => '0',
    'comment' => 'This is a custom field']);
    $setup->endSetup();




    CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




    <?php
    namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;

    class Front


    /**
    * @var Yesno
    */
    protected $_yesNo;

    /**
    * @param MagentoConfigModelConfigSourceYesno $yesNo
    */
    public function __construct(
    MagentoConfigModelConfigSourceYesno $yesNo
    )
    $this->_yesNo = $yesNo;


    /**
    * Get form HTML
    *
    * @return string
    */
    public function aroundGetFormHtml(
    MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
    Closure $proceed
    )


    $yesnoSource = $this->_yesNo->toOptionArray();
    $form = $subject->getForm();
    $fieldset = $form->getElement('front_fieldset');
    $fieldset->addField(
    'my_custom_field',
    'select',
    [
    'name' => 'my_custom_field',
    'label' => __('Label for my custom field'),
    'title' => __('Title for my custom field'),
    'note' => __('Note for my custom field.'),
    'values' => $yesnoSource,
    ]
    );
    return $proceed();





    CompanyName/ModuleName/etc/adminhtml/di.xml




    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront">
    <plugin name="companyname_attribute_edit_form" type="CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront" sortOrder="1"/>
    </type>
    </config>


    enter image description here










    share|improve this question


























      0












      0








      0








      I am adding a custom field to product attributes with a plugin providing the adminhtml display.



      I have it visible in Store -> Attributes -> Product -> Edit attribute and it works okay to save, but when editing a product attribute the stored value is not loaded. The value is initially correctly stored in the database, subsequent visits to edit do not load the saved value from the database.



      How can I have this yesno successfully pull the stored value when an admin is editing the attribute? I'm not sure why the value isn't being pulled with the current one being selected. This is Magento 2.2.7




      CompanyNameModuleNameSetupUpgradeSchema.php




      <?php
      namespace CompanyNameModuleNameSetup;
      use MagentoFrameworkSetupUpgradeSchemaInterface;
      use MagentoFrameworkSetupModuleContextInterface;
      use MagentoFrameworkSetupSchemaSetupInterface;
      class UpgradeSchema implements UpgradeSchemaInterface
      public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
      if (version_compare($context->getVersion(), '1.0.1') < 0)
      $setup->startSetup();
      $setup->getConnection()->addColumn(
      $setup->getTable('catalog_eav_attribute'),
      'my_custom_field',
      ['type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
      'length' => '1',
      'nullable' => false,
      'unsigned' => true,
      'default' => '0',
      'comment' => 'This is a custom field']);
      $setup->endSetup();




      CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




      <?php
      namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;

      class Front


      /**
      * @var Yesno
      */
      protected $_yesNo;

      /**
      * @param MagentoConfigModelConfigSourceYesno $yesNo
      */
      public function __construct(
      MagentoConfigModelConfigSourceYesno $yesNo
      )
      $this->_yesNo = $yesNo;


      /**
      * Get form HTML
      *
      * @return string
      */
      public function aroundGetFormHtml(
      MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
      Closure $proceed
      )


      $yesnoSource = $this->_yesNo->toOptionArray();
      $form = $subject->getForm();
      $fieldset = $form->getElement('front_fieldset');
      $fieldset->addField(
      'my_custom_field',
      'select',
      [
      'name' => 'my_custom_field',
      'label' => __('Label for my custom field'),
      'title' => __('Title for my custom field'),
      'note' => __('Note for my custom field.'),
      'values' => $yesnoSource,
      ]
      );
      return $proceed();





      CompanyName/ModuleName/etc/adminhtml/di.xml




      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront">
      <plugin name="companyname_attribute_edit_form" type="CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront" sortOrder="1"/>
      </type>
      </config>


      enter image description here










      share|improve this question
















      I am adding a custom field to product attributes with a plugin providing the adminhtml display.



      I have it visible in Store -> Attributes -> Product -> Edit attribute and it works okay to save, but when editing a product attribute the stored value is not loaded. The value is initially correctly stored in the database, subsequent visits to edit do not load the saved value from the database.



      How can I have this yesno successfully pull the stored value when an admin is editing the attribute? I'm not sure why the value isn't being pulled with the current one being selected. This is Magento 2.2.7




      CompanyNameModuleNameSetupUpgradeSchema.php




      <?php
      namespace CompanyNameModuleNameSetup;
      use MagentoFrameworkSetupUpgradeSchemaInterface;
      use MagentoFrameworkSetupModuleContextInterface;
      use MagentoFrameworkSetupSchemaSetupInterface;
      class UpgradeSchema implements UpgradeSchemaInterface
      public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
      if (version_compare($context->getVersion(), '1.0.1') < 0)
      $setup->startSetup();
      $setup->getConnection()->addColumn(
      $setup->getTable('catalog_eav_attribute'),
      'my_custom_field',
      ['type' => MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
      'length' => '1',
      'nullable' => false,
      'unsigned' => true,
      'default' => '0',
      'comment' => 'This is a custom field']);
      $setup->endSetup();




      CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




      <?php
      namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;

      class Front


      /**
      * @var Yesno
      */
      protected $_yesNo;

      /**
      * @param MagentoConfigModelConfigSourceYesno $yesNo
      */
      public function __construct(
      MagentoConfigModelConfigSourceYesno $yesNo
      )
      $this->_yesNo = $yesNo;


      /**
      * Get form HTML
      *
      * @return string
      */
      public function aroundGetFormHtml(
      MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
      Closure $proceed
      )


      $yesnoSource = $this->_yesNo->toOptionArray();
      $form = $subject->getForm();
      $fieldset = $form->getElement('front_fieldset');
      $fieldset->addField(
      'my_custom_field',
      'select',
      [
      'name' => 'my_custom_field',
      'label' => __('Label for my custom field'),
      'title' => __('Title for my custom field'),
      'note' => __('Note for my custom field.'),
      'values' => $yesnoSource,
      ]
      );
      return $proceed();





      CompanyName/ModuleName/etc/adminhtml/di.xml




      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront">
      <plugin name="companyname_attribute_edit_form" type="CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront" sortOrder="1"/>
      </type>
      </config>


      enter image description here







      magento2 product-attribute custom-field






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 11 at 17:32







      2aptech

















      asked Jul 11 at 15:39









      2aptech2aptech

      33 bronze badges




      33 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          0














          If you need to select yes/no value show at selected at edit time than just change the file code of




          CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




          <?php
          namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;


          use MagentoBackendBlockTemplateContext;
          use MagentoBackendBlockWidgetForm;
          use MagentoBackendBlockWidgetFormGeneric;
          use MagentoConfigModelConfigSourceYesno;
          use MagentoCatalogModelEntityAttribute;
          use MagentoEavBlockAdminhtmlAttributePropertyLocker;
          use MagentoFrameworkDataFormFactory;
          use MagentoFrameworkRegistry;

          class Front extends Generic

          /**
          * @var Yesno
          */
          protected $_yesNo;

          /**
          * @param MagentoConfigModelConfigSourceYesno $yesNo
          */
          public function __construct(
          Context $context,
          Registry $registry,
          FormFactory $formFactory,
          Yesno $yesNo,
          PropertyLocker $propertyLocker,
          array $data = []
          )
          $this->_yesNo = $yesNo;
          $this->propertyLocker = $propertyLocker;
          parent::__construct($context, $registry, $formFactory, $data);



          public function aroundGetFormHtml(
          MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
          Closure $proceed
          )
          $attributeObject = $this->_coreRegistry->registry('entity_attribute');
          //Your plugin code
          $yesnoSource = $this->_yesNo->toOptionArray();
          $form = $subject->getForm();
          $fieldset = $form->getElement('front_fieldset');


          $fieldset->addField(
          'my_custom_field',
          'select',
          [
          'name' => 'my_custom_field',
          'label' => __('Label for my custom field'),
          'title' => __('Title for my custom field'),
          'note' => __('Note for my custom field.'),
          'values' => $yesnoSource,
          ]
          );
          $this->_eventManager->dispatch(
          'adminhtml_catalog_product_attribute_edit_frontend_prepare_form',
          ['form' => $form, 'attribute' => $attributeObject]
          );

          $this->setForm($form);
          $form->setValues($attributeObject->getData());
          $this->propertyLocker->lock($form);

          return $proceed();




          if helpful than please give upvote.
          Thanks






          share|improve this answer























          • This works, thank you! Did I miss the registry part which queries for the stored data and then needed the $form ->setvalue to set the data to the select dropdown?

            – 2aptech
            Jul 11 at 21:06













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281767%2fmagento-2-load-database-value-to-custom-field-in-product-attribute%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If you need to select yes/no value show at selected at edit time than just change the file code of




          CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




          <?php
          namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;


          use MagentoBackendBlockTemplateContext;
          use MagentoBackendBlockWidgetForm;
          use MagentoBackendBlockWidgetFormGeneric;
          use MagentoConfigModelConfigSourceYesno;
          use MagentoCatalogModelEntityAttribute;
          use MagentoEavBlockAdminhtmlAttributePropertyLocker;
          use MagentoFrameworkDataFormFactory;
          use MagentoFrameworkRegistry;

          class Front extends Generic

          /**
          * @var Yesno
          */
          protected $_yesNo;

          /**
          * @param MagentoConfigModelConfigSourceYesno $yesNo
          */
          public function __construct(
          Context $context,
          Registry $registry,
          FormFactory $formFactory,
          Yesno $yesNo,
          PropertyLocker $propertyLocker,
          array $data = []
          )
          $this->_yesNo = $yesNo;
          $this->propertyLocker = $propertyLocker;
          parent::__construct($context, $registry, $formFactory, $data);



          public function aroundGetFormHtml(
          MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
          Closure $proceed
          )
          $attributeObject = $this->_coreRegistry->registry('entity_attribute');
          //Your plugin code
          $yesnoSource = $this->_yesNo->toOptionArray();
          $form = $subject->getForm();
          $fieldset = $form->getElement('front_fieldset');


          $fieldset->addField(
          'my_custom_field',
          'select',
          [
          'name' => 'my_custom_field',
          'label' => __('Label for my custom field'),
          'title' => __('Title for my custom field'),
          'note' => __('Note for my custom field.'),
          'values' => $yesnoSource,
          ]
          );
          $this->_eventManager->dispatch(
          'adminhtml_catalog_product_attribute_edit_frontend_prepare_form',
          ['form' => $form, 'attribute' => $attributeObject]
          );

          $this->setForm($form);
          $form->setValues($attributeObject->getData());
          $this->propertyLocker->lock($form);

          return $proceed();




          if helpful than please give upvote.
          Thanks






          share|improve this answer























          • This works, thank you! Did I miss the registry part which queries for the stored data and then needed the $form ->setvalue to set the data to the select dropdown?

            – 2aptech
            Jul 11 at 21:06















          0














          If you need to select yes/no value show at selected at edit time than just change the file code of




          CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




          <?php
          namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;


          use MagentoBackendBlockTemplateContext;
          use MagentoBackendBlockWidgetForm;
          use MagentoBackendBlockWidgetFormGeneric;
          use MagentoConfigModelConfigSourceYesno;
          use MagentoCatalogModelEntityAttribute;
          use MagentoEavBlockAdminhtmlAttributePropertyLocker;
          use MagentoFrameworkDataFormFactory;
          use MagentoFrameworkRegistry;

          class Front extends Generic

          /**
          * @var Yesno
          */
          protected $_yesNo;

          /**
          * @param MagentoConfigModelConfigSourceYesno $yesNo
          */
          public function __construct(
          Context $context,
          Registry $registry,
          FormFactory $formFactory,
          Yesno $yesNo,
          PropertyLocker $propertyLocker,
          array $data = []
          )
          $this->_yesNo = $yesNo;
          $this->propertyLocker = $propertyLocker;
          parent::__construct($context, $registry, $formFactory, $data);



          public function aroundGetFormHtml(
          MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
          Closure $proceed
          )
          $attributeObject = $this->_coreRegistry->registry('entity_attribute');
          //Your plugin code
          $yesnoSource = $this->_yesNo->toOptionArray();
          $form = $subject->getForm();
          $fieldset = $form->getElement('front_fieldset');


          $fieldset->addField(
          'my_custom_field',
          'select',
          [
          'name' => 'my_custom_field',
          'label' => __('Label for my custom field'),
          'title' => __('Title for my custom field'),
          'note' => __('Note for my custom field.'),
          'values' => $yesnoSource,
          ]
          );
          $this->_eventManager->dispatch(
          'adminhtml_catalog_product_attribute_edit_frontend_prepare_form',
          ['form' => $form, 'attribute' => $attributeObject]
          );

          $this->setForm($form);
          $form->setValues($attributeObject->getData());
          $this->propertyLocker->lock($form);

          return $proceed();




          if helpful than please give upvote.
          Thanks






          share|improve this answer























          • This works, thank you! Did I miss the registry part which queries for the stored data and then needed the $form ->setvalue to set the data to the select dropdown?

            – 2aptech
            Jul 11 at 21:06













          0












          0








          0







          If you need to select yes/no value show at selected at edit time than just change the file code of




          CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




          <?php
          namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;


          use MagentoBackendBlockTemplateContext;
          use MagentoBackendBlockWidgetForm;
          use MagentoBackendBlockWidgetFormGeneric;
          use MagentoConfigModelConfigSourceYesno;
          use MagentoCatalogModelEntityAttribute;
          use MagentoEavBlockAdminhtmlAttributePropertyLocker;
          use MagentoFrameworkDataFormFactory;
          use MagentoFrameworkRegistry;

          class Front extends Generic

          /**
          * @var Yesno
          */
          protected $_yesNo;

          /**
          * @param MagentoConfigModelConfigSourceYesno $yesNo
          */
          public function __construct(
          Context $context,
          Registry $registry,
          FormFactory $formFactory,
          Yesno $yesNo,
          PropertyLocker $propertyLocker,
          array $data = []
          )
          $this->_yesNo = $yesNo;
          $this->propertyLocker = $propertyLocker;
          parent::__construct($context, $registry, $formFactory, $data);



          public function aroundGetFormHtml(
          MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
          Closure $proceed
          )
          $attributeObject = $this->_coreRegistry->registry('entity_attribute');
          //Your plugin code
          $yesnoSource = $this->_yesNo->toOptionArray();
          $form = $subject->getForm();
          $fieldset = $form->getElement('front_fieldset');


          $fieldset->addField(
          'my_custom_field',
          'select',
          [
          'name' => 'my_custom_field',
          'label' => __('Label for my custom field'),
          'title' => __('Title for my custom field'),
          'note' => __('Note for my custom field.'),
          'values' => $yesnoSource,
          ]
          );
          $this->_eventManager->dispatch(
          'adminhtml_catalog_product_attribute_edit_frontend_prepare_form',
          ['form' => $form, 'attribute' => $attributeObject]
          );

          $this->setForm($form);
          $form->setValues($attributeObject->getData());
          $this->propertyLocker->lock($form);

          return $proceed();




          if helpful than please give upvote.
          Thanks






          share|improve this answer













          If you need to select yes/no value show at selected at edit time than just change the file code of




          CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTabFront.php




          <?php
          namespace CompanyNameModuleNamePluginBlockAdminhtmlProductAttributeEditTab;


          use MagentoBackendBlockTemplateContext;
          use MagentoBackendBlockWidgetForm;
          use MagentoBackendBlockWidgetFormGeneric;
          use MagentoConfigModelConfigSourceYesno;
          use MagentoCatalogModelEntityAttribute;
          use MagentoEavBlockAdminhtmlAttributePropertyLocker;
          use MagentoFrameworkDataFormFactory;
          use MagentoFrameworkRegistry;

          class Front extends Generic

          /**
          * @var Yesno
          */
          protected $_yesNo;

          /**
          * @param MagentoConfigModelConfigSourceYesno $yesNo
          */
          public function __construct(
          Context $context,
          Registry $registry,
          FormFactory $formFactory,
          Yesno $yesNo,
          PropertyLocker $propertyLocker,
          array $data = []
          )
          $this->_yesNo = $yesNo;
          $this->propertyLocker = $propertyLocker;
          parent::__construct($context, $registry, $formFactory, $data);



          public function aroundGetFormHtml(
          MagentoCatalogBlockAdminhtmlProductAttributeEditTabFront $subject,
          Closure $proceed
          )
          $attributeObject = $this->_coreRegistry->registry('entity_attribute');
          //Your plugin code
          $yesnoSource = $this->_yesNo->toOptionArray();
          $form = $subject->getForm();
          $fieldset = $form->getElement('front_fieldset');


          $fieldset->addField(
          'my_custom_field',
          'select',
          [
          'name' => 'my_custom_field',
          'label' => __('Label for my custom field'),
          'title' => __('Title for my custom field'),
          'note' => __('Note for my custom field.'),
          'values' => $yesnoSource,
          ]
          );
          $this->_eventManager->dispatch(
          'adminhtml_catalog_product_attribute_edit_frontend_prepare_form',
          ['form' => $form, 'attribute' => $attributeObject]
          );

          $this->setForm($form);
          $form->setValues($attributeObject->getData());
          $this->propertyLocker->lock($form);

          return $proceed();




          if helpful than please give upvote.
          Thanks







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 11 at 17:08









          Rasik MiyaniRasik Miyani

          1479 bronze badges




          1479 bronze badges












          • This works, thank you! Did I miss the registry part which queries for the stored data and then needed the $form ->setvalue to set the data to the select dropdown?

            – 2aptech
            Jul 11 at 21:06

















          • This works, thank you! Did I miss the registry part which queries for the stored data and then needed the $form ->setvalue to set the data to the select dropdown?

            – 2aptech
            Jul 11 at 21:06
















          This works, thank you! Did I miss the registry part which queries for the stored data and then needed the $form ->setvalue to set the data to the select dropdown?

          – 2aptech
          Jul 11 at 21:06





          This works, thank you! Did I miss the registry part which queries for the stored data and then needed the $form ->setvalue to set the data to the select dropdown?

          – 2aptech
          Jul 11 at 21:06

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281767%2fmagento-2-load-database-value-to-custom-field-in-product-attribute%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form