Drupal 8 has a generic Entity reference field included in core, and, until Drupal 8.0.0-beta10, it also had the old Taxonomy reference field from Drupal 7. In order to reduce code duplication and improve the developer and site-building experience, the Taxonomy reference field has been removed.
The main differences that developers and site builders need to be aware of are the following:
Checking if a field storage is a taxonomy reference field
Before
if ($field_storage->getType() == 'taxonomy_term_reference') { ... }
After
if ($field_storage->getType() == 'entity_reference' && $field_storage->getSetting('target_type') == 'taxonomy_term') { ... }
Creating a taxonomy reference field programatically
Note that this is usually done in tests; for production code, configurable fields should be managed through the configuration system.
Before
FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->id(),
'parent' => '0',
),
),
),
))->save();
FieldConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'article',
))->save();
After
FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'entity_reference',
'settings' => array(
'target_type' => 'taxonomy_term',
),
))->save();
FieldConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'article',
'settings' => array(
'handler_settings' => array(
'target_bundles' => array(
$vocabulary->id() => $vocabulary->id(),
),
'auto_create' => TRUE,
),
),
))->save();
Updating field widgets and formatters
Widgets
Before | After |
---|---|
Autocomplete term widget (tagging) taxonomy_autocomplete |
Autocomplete (Tags style) entity_reference_autocomplete_tags |
Formatters
Before | After |
---|---|
Plain text taxonomy_term_reference_plain |
Label entity_reference_label |
Link taxonomy_term_reference_link |
Label (with the "Link label to the referenced entity" setting enabled) entity_reference_label |
RSS category taxonomy_term_reference_rss_category |
RSS category entity_reference_rss_category |
Updating Taxonomy field data from Drupal 8.0.0-beta9 or earlier
Existing Drupal 8 beta sites can update data in existing taxonomy fields using a proposed patch for the head2head module:
#2456419: Upgrade to Drupal 8 and provide a beta2beta submodule
Note that a beta-to-beta upgrade path is not yet supported in Drupal 8 core, so the head2head update should be considered unstable and tested thoroughly. For more information see: