1 taxonomy.module taxonomy_config_create_validate(Config $staging_config, $all_changes)

Implements hook_config_create_validate().

Related topics

File

core/modules/taxonomy/taxonomy.module, line 2164
Enables the organization of content into categories.

Code

function taxonomy_config_create_validate(Config $staging_config, $all_changes) {
  $config_name = $staging_config->getName();

  // Ensure the taxonomy vocabulary exists before importing fields.
  // First, check this is a config file for a taxonomy vocabulary field.
  if (strpos($config_name, 'field.instance.taxonomy_term.') === 0) {
    list($vocabulary_name, $field_name) = explode('.', str_replace('field.instance.taxonomy_term.', '', $config_name));

    // Check that the vocabulary does or will exist.
    $vocabulary_exists = (bool) taxonomy_vocabulary_load($vocabulary_name);
    $vocabulary_created = isset($all_changes['taxonomy.vocabulary.' . $vocabulary_name]);
    if (!$vocabulary_exists && !$vocabulary_created) {
      throw new ConfigValidateException(t('The field "@name" cannot be added because the vocabulary "@vocabulary" does not exist.', array('@name' => $field_name, '@vocabulary' => $vocabulary_name)));
    }
  }
}