0

I have created a custom module that allows to subscribe to some news.

Each user ( and there will be thousands of them ) can register to some news category using that form

enter image description here

On form submit, the couple [loti, emails] is stored in a config object, as such:

 public function addSubscriberFromLot($lot, $userEmail) {
    $config = \Drupal::configFactory()
      ->getEditable('my_module_news_subscription.settings');
    $subscribersforLot = $config->get($lot);
    if ($subscribersforLot === null) {
      $config->set($lot, [$userEmail])->save();
    }
    elseif ($subscribersforLot !== null && !(in_array($userEmail, $subscribersforLot))) {
      array_push($subscribersforLot, $userEmail);
      $config->set($lot, $subscribersforLot)->save();
    }
  }

the config schema being

my_module_news_subscription.settings:
  type: mapping
  mapping:
    lot1:
      type: sequence
      label: ‘lot 1’
      sequence:
        type: string
        label: 'Email of subscribers'
    lot2:
      type: sequence
      label: ‘lot 2’
      sequence:
        type: string
        label: 'Email of subscribers'
    lot3:
      type: sequence
      label: ‘lot 3’
      sequence:
        type: string
        label: 'Email of subscribers'
    lot4:
      type: sequence
      label: ‘lot 4’
      sequence:
        type: string
        label: 'Email of subscribers'
    lot5:
      type: sequence
      label: ‘lot 5’
      sequence:
        type: string
        label: 'Email of subscribers'

Is there anything wrong with using that config object for that purpose ?

Can this withstand thousands of entries ?

Is there a more adapted way of store that datas ?

1 Answer 1

1

Configuration defines your site. Users are not configuration, so neither would per-user settings be configuration.

If you need to save data per user, you can use the user.data service.

2

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.