class VocabularyStorageController

Defines a controller class for taxonomy vocabularies.

Hierarchy

Expanded class hierarchy of VocabularyStorageController

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php, line 16
Definition of VocabularyStorageController.

Namespace

Drupal\taxonomy
View source
class VocabularyStorageController extends DatabaseStorageController {

  /**
   * Overrides Drupal\Core\Entity\DatabaseStorageController::buildQuery().
   */
  protected function buildQuery($ids, $revision_id = FALSE) {
    $query = parent::buildQuery($ids, $revision_id);
    $query
      ->addTag('translatable');
    $query
      ->orderBy('base.weight');
    $query
      ->orderBy('base.name');
    return $query;
  }

  /**
   * Overrides Drupal\Core\Entity\DatabaseStorageController::postSave().
   */
  protected function postSave(EntityInterface $entity, $update) {
    if (!$update) {
      field_attach_create_bundle('taxonomy_term', $entity->machine_name);
    }
    elseif ($entity->original->machine_name != $entity->machine_name) {
      field_attach_rename_bundle('taxonomy_term', $entity->original->machine_name, $entity->machine_name);
    }
  }

  /**
   * Overrides Drupal\Core\Entity\DatabaseStorageController::preDelete().
   */
  protected function preDelete($entities) {

    // Only load terms without a parent, child terms will get deleted too.
    $tids = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid IN (:vids) AND th.parent = 0', array(
      ':vids' => array_keys($entities),
    ))
      ->fetchCol();
    taxonomy_term_delete_multiple($tids);
  }

  /**
   * Overrides Drupal\Core\Entity\DatabaseStorageController::postDelete().
   */
  protected function postDelete($entities) {

    // Load all Taxonomy module fields and delete those which use only this
    // vocabulary.
    $taxonomy_fields = field_read_fields(array(
      'module' => 'taxonomy',
    ));
    foreach ($taxonomy_fields as $field_name => $taxonomy_field) {
      $modified_field = FALSE;

      // Term reference fields may reference terms from more than one
      // vocabulary.
      foreach ($taxonomy_field['settings']['allowed_values'] as $key => $allowed_value) {
        foreach ($entities as $vocabulary) {
          if ($allowed_value['vocabulary'] == $vocabulary->machine_name) {
            unset($taxonomy_field['settings']['allowed_values'][$key]);
            $modified_field = TRUE;
          }
        }
      }
      if ($modified_field) {
        if (empty($taxonomy_field['settings']['allowed_values'])) {
          field_delete_field($field_name);
        }
        else {

          // Update the field definition with the new allowed values.
          field_update_field($taxonomy_field);
        }
      }
    }
  }

  /**
   * Overrides Drupal\Core\Entity\DrupalDatabaseStorageController::resetCache().
   */
  public function resetCache(array $ids = NULL) {
    drupal_static_reset('taxonomy_vocabulary_get_names');
    parent::resetCache($ids);
    cache_invalidate_tags(array(
      'content' => TRUE,
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DatabaseStorageController::$cache protected property Whether this entity type should use the static cache.
DatabaseStorageController::$entityCache protected property Static cache of entities.
DatabaseStorageController::$entityFieldInfo protected property An array of field information, i.e. containing definitions.
DatabaseStorageController::$entityInfo protected property Array of information about the entity.
DatabaseStorageController::$entityType protected property Entity type for this controller instance.
DatabaseStorageController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DatabaseStorageController::$idKey protected property Name of the entity's ID field in the entity database table.
DatabaseStorageController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DatabaseStorageController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DatabaseStorageController::$uuidKey protected property Name of entity's UUID database table field, if it supports UUIDs.
DatabaseStorageController::attachLoad protected function Attaches data to entities upon loading. 4
DatabaseStorageController::baseFieldDefinitions public function Defines the base properties of the entity type. 1
DatabaseStorageController::buildPropertyQuery protected function Builds an entity query. 2
DatabaseStorageController::cacheGet protected function Gets entities from the static cache.
DatabaseStorageController::cacheSet protected function Stores entities in the static entity cache.
DatabaseStorageController::create public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::create(). Overrides EntityStorageControllerInterface::create 5
DatabaseStorageController::delete public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::delete(). Overrides EntityStorageControllerInterface::delete
DatabaseStorageController::deleteRevision public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::deleteRevision(). Overrides EntityStorageControllerInterface::deleteRevision
DatabaseStorageController::getFieldDefinitions public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::getFieldDefinitions(). Overrides EntityStorageControllerInterface::getFieldDefinitions
DatabaseStorageController::getQueryServiceName public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServiceName().
DatabaseStorageController::invokeHook protected function Invokes a hook on behalf of the entity. 2
DatabaseStorageController::load public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::load(). Overrides EntityStorageControllerInterface::load
DatabaseStorageController::loadByProperties public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadByProperties(). Overrides EntityStorageControllerInterface::loadByProperties
DatabaseStorageController::loadRevision public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadRevision(). Overrides EntityStorageControllerInterface::loadRevision
DatabaseStorageController::preSave protected function Acts on an entity before the presave hook is invoked. 4
DatabaseStorageController::preSaveRevision protected function Act on a revision before being saved. 2
DatabaseStorageController::save public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::save(). Overrides EntityStorageControllerInterface::save 2
DatabaseStorageController::saveRevision protected function Saves an entity revision. 1
DatabaseStorageController::__construct public function Constructs a DatabaseStorageController object. 1
EntityStorageControllerInterface::getQueryServicename public function Gets the name of the service for the query for this entity storage. 1
VocabularyStorageController::buildQuery protected function Overrides Drupal\Core\Entity\DatabaseStorageController::buildQuery(). Overrides DatabaseStorageController::buildQuery
VocabularyStorageController::postDelete protected function Overrides Drupal\Core\Entity\DatabaseStorageController::postDelete(). Overrides DatabaseStorageController::postDelete
VocabularyStorageController::postSave protected function Overrides Drupal\Core\Entity\DatabaseStorageController::postSave(). Overrides DatabaseStorageController::postSave
VocabularyStorageController::preDelete protected function Overrides Drupal\Core\Entity\DatabaseStorageController::preDelete(). Overrides DatabaseStorageController::preDelete
VocabularyStorageController::resetCache public function Overrides Drupal\Core\Entity\DrupalDatabaseStorageController::resetCache(). Overrides DatabaseStorageController::resetCache