i am having a form with 2 values to save on submit:

 public function submitForm(array &$form, FormStateInterface $form_state) {
    if ($_POST['op'] == 'Import Accounts') {
      $filter = $form_state->getValue('ldap_filter');
        ->set('ldap_filter', $filter)

      $roles = $form_state->getValue('roles_list');
        ->set('roles', $roles)

It is working but each save override the previous one.

How can i structure the yml to save a list of datas iterately


ldap_filter: ""
roles: null

i have been trying a schema file although i am not sure it if it is considered at all


  type: config_object
  label: 'couple filtreLDAP / roles'
      type: text
      label: 'Filtre LDAP'
      type: array
      label: 'Rôles'

i have seen things like



1 Answer 1


Config items can be arrays, so something like this should work. (Note that I haven't actually set it up to try it).

      $new_filter = $form_state->getValue('ldap_filter');
      $filters = \Drupal::configFactory()->getEditable('amu_import_ldap.settings')
      $filters[] = $new_filter;
        ->set('ldap_filter', $filters)

Of course that's a very naive example, you may wish to check you are only adding unique items to the array, and so on.

  • thanks the same simple solution stroke my mind overnight :)
    – Matoeil
    Mar 27, 2020 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.