Magento 2, get field backend model by path The Next CEO of Stack OverflowMagento model extension experiment, return: “class does not exist”get Product not work - Magento 2Magento 2: Plugin class does not existMagento 2 get Area CodeMagento 2: Can't install or uninstall plugins in magento 2How to get the value of field in backend model of another field in magento 2 admin configuration?Get system config values in magento 2 without constructorMagento2 REST API get all customers detailsMagento 2 plugin change price of products that have a custom attribute withMagento Website Error

What is the difference between 'contrib' and 'non-free' packages repositories?

Read/write a pipe-delimited file line by line with some simple text manipulation

Shortening a title without changing its meaning

"Eavesdropping" vs "Listen in on"

Is a distribution that is normal, but highly skewed, considered Gaussian?

Free fall ellipse or parabola?

What happens if you break a law in another country outside of that country?

How to find if SQL server backup is encrypted with TDE without restoring the backup

Man transported from Alternate World into ours by a Neutrino Detector

How does a dynamic QR code work?

Can this transistor (2N2222) take 6 V on emitter-base? Am I reading the datasheet incorrectly?

Strange use of "whether ... than ..." in official text

How to show a landlord what we have in savings?

Why does sin(x) - sin(y) equal this?

What did the word "leisure" mean in late 18th Century usage?

Gödel's incompleteness theorems - what are the religious implications?

What is a typical Mizrachi Seder like?

Does int main() need a declaration on C++?

Early programmable calculators with RS-232

Can I hook these wires up to find the connection to a dead outlet?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact

Why doesn't Shulchan Aruch include the laws of destroying fruit trees?

Is there a rule of thumb for determining the amount one should accept for a settlement offer?



Magento 2, get field backend model by path



The Next CEO of Stack OverflowMagento model extension experiment, return: “class does not exist”get Product not work - Magento 2Magento 2: Plugin class does not existMagento 2 get Area CodeMagento 2: Can't install or uninstall plugins in magento 2How to get the value of field in backend model of another field in magento 2 admin configuration?Get system config values in magento 2 without constructorMagento2 REST API get all customers detailsMagento 2 plugin change price of products that have a custom attribute withMagento Website Error










0















I'm making a plugin for the MagentoFrameworkAppConfigScopeConfigInterface file.



I need to get the config value from database.



Right now, I manage to accomplish this, but I'm having an issue with obscured fields.



I'm getting the value that comes directly from database.



If I inject the EncryptorInterface I can decrypt it, but the problem is that I need to know when is necessary to decrypt and when should I need to return the value from database.



I have at this point of the flow the path for the config option (example: carriers/usps/userid )



I was looking for a way to detect the backend model for the field using the path to load the model.



I tried something like this:



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$field = $objectManager->create('MagentoConfigModelConfigStructure')->getElement($path);


And then try this to get the backend Model:



 if ($field->hasBackendModel()) 
$backendModel = $field->getBackendModel();
//backend model is empty



Not sure how I can achieve to detect if the field has backend model MagentoConfigModelConfigBackendEncrypted



Is there some way to read the xml tree, and using the field path get the backend model, so I can know if I should use decrypt for returning the value or not?










share|improve this question




























    0















    I'm making a plugin for the MagentoFrameworkAppConfigScopeConfigInterface file.



    I need to get the config value from database.



    Right now, I manage to accomplish this, but I'm having an issue with obscured fields.



    I'm getting the value that comes directly from database.



    If I inject the EncryptorInterface I can decrypt it, but the problem is that I need to know when is necessary to decrypt and when should I need to return the value from database.



    I have at this point of the flow the path for the config option (example: carriers/usps/userid )



    I was looking for a way to detect the backend model for the field using the path to load the model.



    I tried something like this:



    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $field = $objectManager->create('MagentoConfigModelConfigStructure')->getElement($path);


    And then try this to get the backend Model:



     if ($field->hasBackendModel()) 
    $backendModel = $field->getBackendModel();
    //backend model is empty



    Not sure how I can achieve to detect if the field has backend model MagentoConfigModelConfigBackendEncrypted



    Is there some way to read the xml tree, and using the field path get the backend model, so I can know if I should use decrypt for returning the value or not?










    share|improve this question


























      0












      0








      0








      I'm making a plugin for the MagentoFrameworkAppConfigScopeConfigInterface file.



      I need to get the config value from database.



      Right now, I manage to accomplish this, but I'm having an issue with obscured fields.



      I'm getting the value that comes directly from database.



      If I inject the EncryptorInterface I can decrypt it, but the problem is that I need to know when is necessary to decrypt and when should I need to return the value from database.



      I have at this point of the flow the path for the config option (example: carriers/usps/userid )



      I was looking for a way to detect the backend model for the field using the path to load the model.



      I tried something like this:



      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $field = $objectManager->create('MagentoConfigModelConfigStructure')->getElement($path);


      And then try this to get the backend Model:



       if ($field->hasBackendModel()) 
      $backendModel = $field->getBackendModel();
      //backend model is empty



      Not sure how I can achieve to detect if the field has backend model MagentoConfigModelConfigBackendEncrypted



      Is there some way to read the xml tree, and using the field path get the backend model, so I can know if I should use decrypt for returning the value or not?










      share|improve this question
















      I'm making a plugin for the MagentoFrameworkAppConfigScopeConfigInterface file.



      I need to get the config value from database.



      Right now, I manage to accomplish this, but I'm having an issue with obscured fields.



      I'm getting the value that comes directly from database.



      If I inject the EncryptorInterface I can decrypt it, but the problem is that I need to know when is necessary to decrypt and when should I need to return the value from database.



      I have at this point of the flow the path for the config option (example: carriers/usps/userid )



      I was looking for a way to detect the backend model for the field using the path to load the model.



      I tried something like this:



      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $field = $objectManager->create('MagentoConfigModelConfigStructure')->getElement($path);


      And then try this to get the backend Model:



       if ($field->hasBackendModel()) 
      $backendModel = $field->getBackendModel();
      //backend model is empty



      Not sure how I can achieve to detect if the field has backend model MagentoConfigModelConfigBackendEncrypted



      Is there some way to read the xml tree, and using the field path get the backend model, so I can know if I should use decrypt for returning the value or not?







      magento2 backend plugin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 5 hours ago









      Ronak Rathod

      869112




      869112










      asked 15 hours ago









      Matias DelgadoMatias Delgado

      104




      104




















          1 Answer
          1






          active

          oldest

          votes


















          0














          You need to add backend_model in config.xml for those filed which type obscure.



          Ex:



          <field id="account" translate="label comment" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
          <label>Account ID</label>
          <backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model>
          </field>


          You need to add in confix.xml like:



          <account backend_model="MagentoConfigModelConfigBackendEncrypted">TEST</account>


          For more detail check dhl module



          Now when you use the following code, Magento will return actual value not encrypted value:



          $this->scopeConfig->getValue('yoursection/yourgroup/yourfield')





          share|improve this answer























          • Hi Sohel! I know how to use an encrypted field, but what I need to solve is to get an already existing field, using the path, and see somehow if it should be decrypted or not

            – Matias Delgado
            13 hours ago











          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%2f268220%2fmagento-2-get-field-backend-model-by-path%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














          You need to add backend_model in config.xml for those filed which type obscure.



          Ex:



          <field id="account" translate="label comment" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
          <label>Account ID</label>
          <backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model>
          </field>


          You need to add in confix.xml like:



          <account backend_model="MagentoConfigModelConfigBackendEncrypted">TEST</account>


          For more detail check dhl module



          Now when you use the following code, Magento will return actual value not encrypted value:



          $this->scopeConfig->getValue('yoursection/yourgroup/yourfield')





          share|improve this answer























          • Hi Sohel! I know how to use an encrypted field, but what I need to solve is to get an already existing field, using the path, and see somehow if it should be decrypted or not

            – Matias Delgado
            13 hours ago















          0














          You need to add backend_model in config.xml for those filed which type obscure.



          Ex:



          <field id="account" translate="label comment" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
          <label>Account ID</label>
          <backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model>
          </field>


          You need to add in confix.xml like:



          <account backend_model="MagentoConfigModelConfigBackendEncrypted">TEST</account>


          For more detail check dhl module



          Now when you use the following code, Magento will return actual value not encrypted value:



          $this->scopeConfig->getValue('yoursection/yourgroup/yourfield')





          share|improve this answer























          • Hi Sohel! I know how to use an encrypted field, but what I need to solve is to get an already existing field, using the path, and see somehow if it should be decrypted or not

            – Matias Delgado
            13 hours ago













          0












          0








          0







          You need to add backend_model in config.xml for those filed which type obscure.



          Ex:



          <field id="account" translate="label comment" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
          <label>Account ID</label>
          <backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model>
          </field>


          You need to add in confix.xml like:



          <account backend_model="MagentoConfigModelConfigBackendEncrypted">TEST</account>


          For more detail check dhl module



          Now when you use the following code, Magento will return actual value not encrypted value:



          $this->scopeConfig->getValue('yoursection/yourgroup/yourfield')





          share|improve this answer













          You need to add backend_model in config.xml for those filed which type obscure.



          Ex:



          <field id="account" translate="label comment" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
          <label>Account ID</label>
          <backend_model>MagentoConfigModelConfigBackendEncrypted</backend_model>
          </field>


          You need to add in confix.xml like:



          <account backend_model="MagentoConfigModelConfigBackendEncrypted">TEST</account>


          For more detail check dhl module



          Now when you use the following code, Magento will return actual value not encrypted value:



          $this->scopeConfig->getValue('yoursection/yourgroup/yourfield')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 15 hours ago









          Sohel RanaSohel Rana

          22.9k34460




          22.9k34460












          • Hi Sohel! I know how to use an encrypted field, but what I need to solve is to get an already existing field, using the path, and see somehow if it should be decrypted or not

            – Matias Delgado
            13 hours ago

















          • Hi Sohel! I know how to use an encrypted field, but what I need to solve is to get an already existing field, using the path, and see somehow if it should be decrypted or not

            – Matias Delgado
            13 hours ago
















          Hi Sohel! I know how to use an encrypted field, but what I need to solve is to get an already existing field, using the path, and see somehow if it should be decrypted or not

          – Matias Delgado
          13 hours ago





          Hi Sohel! I know how to use an encrypted field, but what I need to solve is to get an already existing field, using the path, and see somehow if it should be decrypted or not

          – Matias Delgado
          13 hours ago

















          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%2f268220%2fmagento-2-get-field-backend-model-by-path%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

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

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?