I have defined a config entity in my module (schema and class that extends ConfigEntityBase) - MyConfigEntity.

When I use config factory to get config, Drupal returns instance of Config or ImmutableConfig. How can I retrieve instance of MyConfigEntity instead?

$config = \Drupal::config('my_module.config.something');
// Now $config is instance of ImmutableConfig.
  • this is a duplicate: see drupal.stackexchange.com/questions/203371/… – oknate Jun 23 '16 at 20:38
  • @oknate No it's not. My question is specifically about config entities. – SiliconMind Jun 23 '16 at 22:38
  • OK, I stand corrected. I didn't know there was a config entity vs. a config. What are config entities used for? – oknate Jun 24 '16 at 14:31
  • Ah, after poking a round, the big advantage for config entities is they are stored in yml and can be exported, where other entities, such as nodes, cannot be. – oknate Jun 24 '16 at 15:18
  • @oknate for example node type is a config entity. Same as taxonomy vocabulary. You also get CRUD and you can basically handle them like any other entity, for example you can reference them in other entities (that's what node does) – SiliconMind Jun 24 '16 at 15:20


Retrieves a configuration object.

This is the main entry point to the configuration API.

The configuration API is a different system than the entity API.

$entity = \Drupal::entityTypeManager()

Configuration entity types should be used to store configurable content like content types or other site builder-esque things that you want to deploy from environment to environment that is not managed content (Something a content author would write).

If you're looking for a complex configuration object, then you should define that in config/mymodule.settings.yml and use the configuration API like in your question.

| improve this answer | |
  • Damn, that's yet another dependency. – SiliconMind Jun 23 '16 at 20:46

Check this out configFactory.

You just need to do:


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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