Unable to store value of an property or entity key in ConfigEntityType form I have a propay_account_number in config entity type which I am unable to save using the below code.
What is incorrect and how can I fix it to make it work ?



src\Entity\PropayAccount.php
    

namespace Drupal\propay_api\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;

/**
 * Defines the Propay Account entity.
 *
 * @ConfigEntityType(
 *   id = "propay_api_account_number",
 *   label = @Translation("Propay"),
 *   handlers = {
 *     "list_builder" = "Drupal\propay_api\PropayAccountListBuilder",
 *     "form" = {
 *       "add" = "Drupal\propay_api\Form\PropayAccountCreateForm",
 *       "edit" = "Drupal\propay_api\Form\PropayAccountRenewForm",
 *       "delete" = "Drupal\propay_api\Form\PropayAccountDeleteForm",
 *     }
 *   },
 *   config_prefix = "account_number",
 *   admin_permission = "administer site configuration",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "propay_account_number" = "propay_account_number"
 *   },
 *   config_export = {
 *     "id",
 *     "label"
 *   },
 *   links = {
 *     "edit-form" = "/admin/config/development/propay-api/account-number/{propay_api_account_number}",
 *     "delete-form" = "/admin/config/development/propay-api/account-number/{propay_api_account_number}/delete",
 *     "enable" = "/admin/config/development/propay-api/account-number/{propay_api_account_number}/enable",
 *     "disable" = "/admin/config/development/propay-api/account-number/{propay_api_account_number}/disable",
 *   }

 * )
 */

class PropayAccount extends ConfigEntityBase {

    /**
     * The Propay ID.
     *
     * @var string
     */
    protected $id;

    /**
     * The Propay Label.
     *
     * @var string
     */
    protected $label;

    /**
     * The Propay Account Number.
     *
     * @var string
     */
    protected $propay_account_number;


    public function id() {
        return $this-&gt;id;
    }

    public function label(){
        return $this-&gt;label;
    }

    public function getAccountNumber() {
      return $this-&gt;propay_account_number;
    }

}


config\schema\propay_api.schema.yml

propay_api.account_number.*:
  type: config_entity
  label: 'Propay Account Number'
  mapping:
    id:
      type: string
      label: 'ID'
    label:
      type: label
      label: 'Label'
    propay_account_number:
      type: string
      label: 'Propay Account Number'


src\Form\PropayAccountCreateForm.php

    &lt;?php

    /**
     * @file
     * Contains \Drupal\propay_api\Form\PropayAccountCreateForm.
     */

    namespace Drupal\propay_api\Form;


    use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;

class PropayAccountCreateForm extends EntityForm
{

    public function form(array $form, FormStateInterface $form_state)
    {
        $form = parent::form($form, $form_state);

        $entity = $this-&gt;entity;
        $form['id'] = [
            '#type' =&gt; 'textfield',
            '#title' =&gt; $this-&gt;t('ID'),
            '#required' =&gt; TRUE,
            '#default_value' =&gt; ($entity-&gt;id()) ?? '',
        ];

        $form['label'] = [
            '#type' =&gt; 'textfield',
            '#title' =&gt; $this-&gt;t('LABEL'),
            '#required' =&gt; TRUE,
            '#default_value' =&gt; ($entity-&gt;label()) ?? '',
        ];

        $form['propay_account_number'] = [
            '#type' =&gt; 'textfield',
            '#title' =&gt; $this-&gt;t('Propay Account Number'),
            '#required' =&gt; TRUE,
            '#default_value' =&gt; ($entity-&gt;getAccountNumber()) ?? '',
        ];

        return $form;
    }

    public function save($form, FormStateInterface $form_state)
    {
        $entity = $this-&gt;entity;
        $entity-&gt;set('propay_account_number', $form_state-&gt;getValue('propay_account_number'));
        $entity-&gt;save();
    }
//event tried formSubmit() but it did not help save the values in propay_account_number


}
Try this one for saving config.


$config = Drupal::service('config.factory')-&gt;getEditable('my_module.settings');
$config-&gt;set('my_module.dsu_single_indexing_server',json_encode(array_unique($values)))-&gt;save();