Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <tab id="testtab">
  2. <label>Test settings</label>
  3. </tab>
  4. <section id="testsection" type="text" showInDefault="1">
  5. <label>Test Configuration</label>
  6. <tab>testtab</tab>
  7. <resource>Namespace_Modulename::system_config</resource>
  8. <group id="settings" type="text" sortOrder="10" showInDefault="1">
  9. <label>Credentials</label>
  10. <field id="key" translate="label" type="text" sortOrder="30" showInDefault="1">
  11. <label>Key</label>
  12. </field>
  13. </group>
  14. </section>
  15.  
  16. public function configDirective($construction)
  17. {
  18. $configValue = '';
  19. $params = $this->getParameters($construction[2]);
  20. $storeId = $this->getStoreId();
  21. if (isset($params['path']) && $this->isAvailableConfigVariable($params['path'])) {
  22. $configValue = $this->_scopeConfig->getValue(
  23. $params['path'],
  24. MagentoStoreModelScopeInterface::SCOPE_STORE,
  25. $storeId
  26. );
  27. }
  28. return $configValue;
  29. }
  30.  
  31. private function isAvailableConfigVariable($variable)
  32. {
  33. return in_array(
  34. $variable,
  35. array_column($this->configVariables->getData(), 'value')
  36. );
  37. }
  38.  
  39. <type name="MagentoEmailModelSourceVariables">
  40. <plugin name="add-test-credentials" type="[Vendor][Module]PluginModelSourceVariablePlugin" />
  41. </type>
  42.  
  43. <?php
  44. namespace [Vendor][Module]PluginModelSource;
  45.  
  46. use MagentoEmailModelSourceVariables;
  47.  
  48. class VariablePlugin
  49. {
  50. /**
  51. * @param Variables $subject
  52. * @param $data
  53. * @return array
  54. */
  55. public function afterGetData(Variables $subject, $data)
  56. {
  57. $data[] = [
  58. 'value' => 'testsection/settings/key',
  59. 'label' => __('Credentials for test settings') //give it a label that suits you best. This will be listed in the insert custom var popup in the cms pages and blocks (see image below)
  60. ];
  61. return $data;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement