Understanding the difference between Drupal 8 State API and Configuration API

Configuration is a place to store information that you want to synchronize from development to production. This information is often created during site building and is not typically generated by regular users during normal site operation.

    In Drupal 7 we have came across storing settings and configurations in a variable in a way :

    $data = variable_set('test.content_types'. 'value');

    But in drupal 8 , this can be ported to :

    \Drupal::config('test')->set('test_name', 'value');

    Now the settings value set above will be overridden (reset the specific setting of an environment) once we run drush cim on production server.

    We can use the State API, not Configuration API, for storing local variables that shouldn't travel between instances.

    The State API provides a place for developers to store information about the system's state. State information differs from configuration in the following ways:

    • It is specific to an individual environment.
    • You will never want to deploy it between environments.
    • You can reset a system, losing all state. Its configuration remains.

     

      In this talk , we will focus on 
       

      • Understanding the differences between State API and Configuration API
      • Usage of State API :
        • To get a value
        • Get multiple key/value pairs
        • Set a value
        • Set Multiple values
        • Delete a value
           
      • Usage of Configuration API :
        • Reading Configuration
        • Writing Configuration
        • Removing Configuration
        • Best Practices