1

I'm using StateAPI to store some variables that shouldn't be exported as configurations.

These values are stored in the database, in the key_value table.

Is this a "secure" table? Are there tasks (cache-clear or other) that could automatically remove values from this table?

Is it a good idea to create a custom form to let users to set some states? They could be simple strings, or url, and I think that create nodes for this information is too "heavy".

2 Answers 2

4

Is this a "secure" table?

Depends on what you mean by secure.

Are there tasks (cache-clear or other) that could automatically remove values from this table?

No.

Is it a good idea to create a custom form to let users to set some states?

This is kind of looking at it from the wrong direction. States are a solution to an issue. If you have something that is to be stored, for which states are a good solution, then they are good to use. In other words, if you have a form that does something that states would be good for, then use states. Deciding to use states then creating forms for them doesn't really make sense.

1

The state service is never used to store data that is edited by users; it is used to store data necessary for a module the module doesn't expose to users through a form for its settings.
The classic example of using the state service is storing the last time cron tasks have been executed, or the last time a feed has been checked. Those values aren't exposed to users (even the users with a specific permission), and users don't have the possibility to reset those values. They are values required from a site to work, but they aren't imported and exported to a different site.

As for the difference between content and configuration, I would follow this simple rule: If you are storing information about your site that doesn't change so frequently, then it is probably configuration; if then it's information a site editor role would want to edit, then it's content.

To answer your question, no: The information stored with the state service is not automatically deleted after X minutes are passed.

9
  • I agree with you, but there are some exception. I'm working on a site that has, in the footer, a big link to a google form. Only the url of this link should ben editable by the user. Should I use a node only to store this url?
    – arrubiu
    Jun 17, 2017 at 6:57
  • I would use a configuration entity which is editable by user with an administer ... permission.
    – apaderno
    Jun 17, 2017 at 8:11
  • Ok, but if the editor change the conf and I've a deploy? With drush cim this conf is overriden. Perhaphs I should to exclude that conf from export..
    – arrubiu
    Jun 17, 2017 at 9:39
  • It depends. If you want the setting to be the same across Drupal instances, you would use configuration. If you want it to be different, you would use State.
    – Jaypan
    Sep 19, 2017 at 3:37
  • @arrubiu The previous comment was the reply to your question.
    – apaderno
    Sep 19, 2017 at 9:30

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.