You are here

ReferenceStorage.php in Bibliography & Citation 8

Same filename and directory in other branches
  1. 2.0.x modules/bibcite_entity/src/ReferenceStorage.php

File

modules/bibcite_entity/src/ReferenceStorage.php
View source
<?php

namespace Drupal\bibcite_entity;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;

/**
 * Defines a Controller class for reference items.
 */
class ReferenceStorage extends SqlContentEntityStorage {

  /**
   * {@inheritdoc}
   */
  protected function saveToDedicatedTables(ContentEntityInterface $entity, $update = TRUE, $names = []) {
    $citekey = NULL;

    /** @var \Drupal\bibcite_entity\Entity\Reference $entity */
    if ($citekey_item = $entity
      ->get('bibcite_citekey')
      ->get(0)) {
      $citekey = $citekey_item
        ->getValue();
    }
    if (!$citekey && $entity
      ->isNew()) {
      $entity->bibcite_citekey = $entity
        ->generateCitekey();
    }
    return parent::saveToDedicatedTables($entity, $update, $names);
  }

  /**
   * {@inheritdoc}
   */
  public function getCustomTableMapping(ContentEntityTypeInterface $entity_type, array $storage_definitions, $prefix = '') {
    $prefix = $prefix ?: ($this->temporary ? 'tmp_' : '');
    return ReferenceDefaultTableMapping::create($entity_type, $storage_definitions, $prefix);
  }

}

Classes

Namesort descending Description
ReferenceStorage Defines a Controller class for reference items.