function taxonomy_breadcrumb_install in Taxonomy Breadcrumb 8
Same name and namespace in other branches
- 5 taxonomy_breadcrumb.install \taxonomy_breadcrumb_install()
- 6 taxonomy_breadcrumb.install \taxonomy_breadcrumb_install()
- 7 taxonomy_breadcrumb.install \taxonomy_breadcrumb_install()
Implements hook_install().
File
- ./
taxonomy_breadcrumb.install, line 15 - Install file for the taxonomy_breadcrumb module.
Code
function taxonomy_breadcrumb_install() {
// Get all the vocabularies machine name.
$bundles = array_keys(\Drupal::entityTypeManager()
->getStorage('taxonomy_vocabulary')
->loadMultiple());
$entity_type = 'taxonomy_term';
$field_name = 'taxonomy_breadcrumb_path';
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
try {
FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'type' => 'link',
))
->save();
} catch (FieldException $e) {
}
}
foreach ($bundles as $bundle) {
if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
try {
FieldConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'bundle' => $bundle,
'label' => t('Breadcrumb path (taxonomy_breadcrumb)'),
'description' => t('Taxonomy Breadcrumb of this term.'),
'required' => FALSE,
))
->save();
} catch (FieldException $e) {
}
}
}
}