Form.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\EncryptionKey\Block\Adminhtml\Crypt\Key;
  7. /**
  8. * Encryption key change form block
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Form extends \Magento\Backend\Block\Widget\Form\Generic
  14. {
  15. /**
  16. * Add form fields
  17. *
  18. * @return $this
  19. */
  20. protected function _prepareForm()
  21. {
  22. /** @var \Magento\Framework\Data\Form $form */
  23. $form = $this->_formFactory->create(
  24. [
  25. 'data' => [
  26. 'id' => 'edit_form',
  27. 'action' => $this->getData('action'),
  28. 'method' => 'post'
  29. ]
  30. ]
  31. );
  32. $fieldset = $form->addFieldset('main_fieldset', ['legend' => __('New Encryption Key')]);
  33. $fieldset->addField(
  34. 'enc_key_note',
  35. 'note',
  36. ['text' => __('The encryption key is used to protect passwords and other sensitive data.')]
  37. );
  38. $fieldset->addField(
  39. 'generate_random',
  40. 'select',
  41. [
  42. 'name' => 'generate_random',
  43. 'label' => __('Auto-generate a Key'),
  44. 'options' => [0 => __('No'), 1 => __('Yes')],
  45. 'onclick' => "var cryptKey = jQuery('#crypt_key'); var cryptKeyBlock = cryptKey.parent().parent(); ".
  46. "cryptKey.prop('disabled', this.value === '1'); " .
  47. "if (cryptKey.prop('disabled')) { cryptKeyBlock.hide() } " .
  48. "else { cryptKeyBlock.show() }",
  49. 'note' => __('The generated key will be displayed after changing.')
  50. ]
  51. );
  52. $fieldset->addField(
  53. 'crypt_key',
  54. 'text',
  55. ['name' => 'crypt_key', 'label' => __('New Key'), 'style' => 'width:32em;', 'maxlength' => 32]
  56. );
  57. $form->setUseContainer(true);
  58. if ($data = $this->getFormData()) {
  59. $form->addValues($data);
  60. }
  61. $this->setForm($form);
  62. return parent::_prepareForm();
  63. }
  64. }