Drupal 8 - Country name list by code

kenneth
/** @var array $countries */
$countries = \Drupal::service('country_manager')
  ->getList();
// Transform TranslatableMarkup object into a string.
array_walk($countries, function (&$translation) {
  /** @var  Drupal\Core\StringTranslation\TranslatableMarkup $translation */
  $translation = $translation->render();
});
var_dump($countries);

Drupal 8 ships with a service to easily retrieve all countries by code. Be sure to use dependency injection.

RuntimeException: Unable to determine class for field type found in the configuration

kenneth
drush sqlq "DELETE FROM cache_config"
drush sqlq "DELETE FROM config WHERE name = 'field.storage.<module_name>.<field_machine_name>' OR data LIKE '%field.storage.<module_name>.<field_machine_name>%'"
drush sqlq "DELETE FROM config_snapshot  WHERE name = 'field.storage.<module_name>.<field_machine_name>' OR data LIKE '%field.storage.<module_name>.<field_machine_name>%'"

On my case It was happening with "taxonomy_term" module and field named "field_location".

Drupal 8 - Load file entity by URI

kenneth
/* @var \Drupal\file\FileInterface[] $files */
$files = \Drupal::entityTypeManager()
  ->getStorage('file')
  ->loadByProperties(['uri' => $uri]);

 

Subscribe to