Form.php 2.06 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\EncryptionKey\Block\Adminhtml\Crypt\Key;

/**
 * Encryption key change form block
 *
 * @api
 * @since 100.0.2
 */
class Form extends \Magento\Backend\Block\Widget\Form\Generic
{
    /**
     * Add form fields
     *
     * @return $this
     */
    protected function _prepareForm()
    {
        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create(
            [
                'data' => [
                    'id' => 'edit_form',
                    'action' => $this->getData('action'),
                    'method' => 'post'
                ]
            ]
        );
        $fieldset = $form->addFieldset('main_fieldset', ['legend' => __('New Encryption Key')]);
        $fieldset->addField(
            'enc_key_note',
            'note',
            ['text' => __('The encryption key is used to protect passwords and other sensitive data.')]
        );
        $fieldset->addField(
            'generate_random',
            'select',
            [
                'name' => 'generate_random',
                'label' => __('Auto-generate a Key'),
                'options' => [0 => __('No'), 1 => __('Yes')],
                'onclick' => "var cryptKey = jQuery('#crypt_key'); var cryptKeyBlock = cryptKey.parent().parent(); ".
                    "cryptKey.prop('disabled', this.value === '1'); " .
                    "if (cryptKey.prop('disabled')) { cryptKeyBlock.hide() } " .
                    "else { cryptKeyBlock.show() }",
                'note' => __('The generated key will be displayed after changing.')
            ]
        );
        $fieldset->addField(
            'crypt_key',
            'text',
            ['name' => 'crypt_key', 'label' => __('New Key'), 'style' => 'width:32em;', 'maxlength' => 32]
        );
        $form->setUseContainer(true);
        if ($data = $this->getFormData()) {
            $form->addValues($data);
        }
        $this->setForm($form);
        return parent::_prepareForm();
    }
}