Jun 21, 2019 in Drupal 8, Snippets

Config entities are new in drupal 8. The differ a bit from content entities. Here a snippet on how to get the value of a field programmatically.

$storage = \Drupal::entityTypeManager()->getStorage('my_custom_config_entity');
$ids = \Drupal::entityQuery('my_custom_config_entity')->execute();
$List = $storage->loadMultiple($ids);
foreach($ids as $entity) {
  $id = $entity->id();
  $title = $entity->label();
  $custom_field = $entity->get('custom_field'); 
  // See how this line differs from content entities, who would have $entity->get('custom_field')->getString();

More about custom config entities here: https://docs.acquia.com/tutorials/fast-track-drupal-8-coding/define-custom-config-entity/