taxonomy_breadcrumb.install in Taxonomy Breadcrumb 8
Same filename and directory in other branches
Install file for the taxonomy_breadcrumb module.
File
taxonomy_breadcrumb.installView source
<?php
/**
* @file
* Install file for the taxonomy_breadcrumb module.
*/
use Drupal\Core\Field\FieldException;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Implements hook_install().
*/
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) {
}
}
}
}
/**
* Implements hook_uninstall().
*/
function taxonomy_breadcrumb_uninstall() {
// Remove variables.
\Drupal::configFactory()
->getEditable('taxonomy_breadcrumb.settings')
->delete();
// Delete taxonomy term field and its instances.
$entity_type = 'taxonomy_term';
$field_name = 'taxonomy_breadcrumb_path';
$bundles = array_keys(\Drupal::entityTypeManager()
->getStorage('taxonomy_vocabulary')
->loadMultiple());
foreach ($bundles as $bundle) {
if (FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
try {
FieldConfig::loadByName($entity_type, $bundle, $field_name)
->delete();
} catch (FieldException $e) {
}
}
}
if (FieldStorageConfig::loadByName($entity_type, $field_name)) {
try {
FieldStorageConfig::loadByName($entity_type, $field_name)
->delete();
} catch (FieldException $e) {
}
}
}
Functions
Name | Description |
---|---|
taxonomy_breadcrumb_install | Implements hook_install(). |
taxonomy_breadcrumb_uninstall | Implements hook_uninstall(). |