1
  • In which case we will use State API ? Instead of UserData API ?

  • Some Use cases where we will use State API ?

  • Some use cases where we will UserData API?

  • Is there any difference apart from the following?

    • Information stored is not configuration that should be exported.
  • Real world examples for both. Is any popular contrib or core modules using this concepts(except user module) ?

2

You find real world examples for State API in the key_value table under the collection state:

comment.maintain_entity_statistics
field.field.deleted
install_time
locale.translation_last_checked
search_api.index.default_index.has_reindexed
system.cron_last
system.maintenance_mode
update.last_check
webform.version

The first part of the name is usually the module. In these examples they are core and the popular contrib modules Search API and Webform.

In contrast UserData API is obviously specific to the user, not the entire system. You would use it for data you don't want to store in a user field. Because it is easy to add user fields in code and config this service is rarely used in Drupal 8+.

1

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