class ItemStorageController

Controller class for aggregators items.

This extends the Drupal\Core\Entity\DatabaseStorageController class, adding required special handling for feed item entities.

Hierarchy

Expanded class hierarchy of ItemStorageController

File

drupal/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php, line 19
Contains \Drupal\aggregator\ItemStorageController.

Namespace

Drupal\aggregator
View source
class ItemStorageController extends DatabaseStorageControllerNG {

  /**
   * Overrides Drupal\Core\Entity\DataBaseStorageController::create().
   */
  public function create(array $values) {
    $entity = parent::create($values);

    // Set an initial timestamp, this will be overwritten if known.
    $entity->timestamp->value = REQUEST_TIME;
    return $entity;
  }

  /**
   * Overrides Drupal\Core\Entity\DataBaseStorageController::attachLoad().
   */
  protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
    parent::attachLoad($queried_entities, $load_revision);
    foreach ($queried_entities as $item) {
      $item->categories = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = :iid ORDER BY c.title', array(
        ':iid' => $item
          ->id(),
      ))
        ->fetchAll();
    }
  }

  /**
   * Overrides Drupal\Core\Entity\DataBaseStorageController::preDelete().
   */
  protected function preDelete($entities) {
    parent::preDelete($entities);
    db_delete('aggregator_category_item')
      ->condition('iid', array_keys($entities), 'IN')
      ->execute();
  }

  /**
   * Overrides Drupal\Core\Entity\DataBaseStorageController::postSave().
   */
  protected function postSave(EntityInterface $entity, $update) {
    parent::postSave($entity, $update);
    $result = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(
      ':fid' => $entity->fid->value,
    ));
    foreach ($result as $category) {
      db_merge('aggregator_category_item')
        ->key(array(
        'iid' => $entity
          ->id(),
        'cid' => $category->cid,
      ))
        ->execute();
    }
  }

  /**
   * Implements Drupal\Core\Entity\DataBaseStorageControllerNG::baseFieldDefinitions().
   */
  public function baseFieldDefinitions() {
    $fields['iid'] = array(
      'label' => t('ID'),
      'description' => t('The ID of the aggregor item.'),
      'type' => 'integer_field',
      'read-only' => TRUE,
    );
    $fields['fid'] = array(
      'label' => t('Aggregator feed ID'),
      'description' => t('The ID of the aggregator feed.'),
      'type' => 'integer_field',
    );
    $fields['title'] = array(
      'label' => t('Title'),
      'description' => t('The title of the feed item.'),
      'type' => 'string_field',
    );
    $fields['langcode'] = array(
      'label' => t('Language code'),
      'description' => t('The feed item language code.'),
      'type' => 'language_field',
    );
    $fields['link'] = array(
      'label' => t('Link'),
      'description' => t('The link of the feed item.'),
      'type' => 'uri_field',
    );
    $fields['author'] = array(
      'label' => t('Author'),
      'description' => t('The author of the feed item.'),
      'type' => 'string_field',
    );
    $fields['description'] = array(
      'label' => t('Description'),
      'description' => t('The body of the feed item.'),
      'type' => 'string_field',
    );
    $fields['timestamp'] = array(
      'label' => t('Posted timestamp'),
      'description' => t('Posted date of the feed item, as a Unix timestamp.'),
      'type' => 'integer_field',
    );
    $fields['guid'] = array(
      'label' => t('GUID'),
      'description' => t('Unique identifier for the feed item.'),
      'type' => 'string_field',
    );
    return $fields;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DatabaseStorageController::$cache protected property Whether this entity type should use the static cache. Overrides EntityStorageControllerBase::$cache
DatabaseStorageController::$database protected property Active database connection.
DatabaseStorageController::$entityFieldInfo protected property An array of field information, i.e. containing definitions.
DatabaseStorageController::$fieldDefinitions protected property Static cache of field definitions per bundle.
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::createInstance public static function Instantiates a new instance of this entity controller. Overrides EntityControllerInterface::createInstance 2
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::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::postDelete protected function Acts on deleted entities before the delete hook is invoked. 6
DatabaseStorageController::preSave protected function Acts on an entity before the presave hook is invoked. 6
DatabaseStorageController::preSaveRevision protected function Act on a revision before being saved. 3
DatabaseStorageControllerNG::$bundleKey protected property The entity bundle key.
DatabaseStorageControllerNG::$dataTable protected property The table that stores properties, if the entity has multilingual support.
DatabaseStorageControllerNG::$entityClass protected property The entity class to use.
DatabaseStorageControllerNG::attachPropertyData protected function Attaches property data in all languages for translatable properties.
DatabaseStorageControllerNG::buildPropertyQuery protected function Builds an entity query. Overrides DatabaseStorageController::buildPropertyQuery 1
DatabaseStorageControllerNG::buildQuery protected function Builds the query to load the entity. Overrides DatabaseStorageController::buildQuery 1
DatabaseStorageControllerNG::delete public function Overwrites \Drupal\Core\Entity\DatabaseStorageController::delete(). Overrides DatabaseStorageController::delete
DatabaseStorageControllerNG::invokeHook protected function Overrides DatabaseStorageController::invokeHook(). Overrides DatabaseStorageController::invokeHook 2
DatabaseStorageControllerNG::mapFromStorageRecords protected function Maps from storage records to entity objects.
DatabaseStorageControllerNG::mapToDataStorageRecord protected function Maps from an entity object to the storage record of the data table. 1
DatabaseStorageControllerNG::mapToRevisionStorageRecord protected function Maps from an entity object to the storage record of the revision table.
DatabaseStorageControllerNG::mapToStorageRecord protected function Maps from an entity object to the storage record of the base table.
DatabaseStorageControllerNG::save public function Overrides DatabaseStorageController::save(). Overrides DatabaseStorageController::save 1
DatabaseStorageControllerNG::savePropertyData protected function Stores the entity property language-aware data.
DatabaseStorageControllerNG::saveRevision protected function Saves an entity revision. Overrides DatabaseStorageController::saveRevision
DatabaseStorageControllerNG::__construct public function Overrides DatabaseStorageController::__construct(). Overrides DatabaseStorageController::__construct 1
EntityStorageControllerBase::$entityCache protected property Static cache of entities.
EntityStorageControllerBase::$entityInfo protected property Array of information about the entity.
EntityStorageControllerBase::$entityType protected property Entity type for this controller instance.
EntityStorageControllerBase::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
EntityStorageControllerBase::$idKey protected property Name of the entity's ID field in the entity database table.
EntityStorageControllerBase::$uuidKey protected property Name of entity's UUID database table field, if it supports UUIDs. 1
EntityStorageControllerBase::cacheGet protected function Gets entities from the static cache.
EntityStorageControllerBase::cacheSet protected function Stores entities in the static entity cache.
EntityStorageControllerBase::loadUnchanged public function Loads an unchanged entity from the database. Overrides EntityStorageControllerInterface::loadUnchanged
EntityStorageControllerBase::resetCache public function Resets the internal, static entity cache. Overrides EntityStorageControllerInterface::resetCache 3
EntityStorageControllerInterface::getQueryServicename public function Gets the name of the service for the query for this entity storage. 1
ItemStorageController::attachLoad protected function Overrides Drupal\Core\Entity\DataBaseStorageController::attachLoad(). Overrides DatabaseStorageControllerNG::attachLoad
ItemStorageController::baseFieldDefinitions public function Implements Drupal\Core\Entity\DataBaseStorageControllerNG::baseFieldDefinitions(). Overrides DatabaseStorageController::baseFieldDefinitions
ItemStorageController::create public function Overrides Drupal\Core\Entity\DataBaseStorageController::create(). Overrides DatabaseStorageControllerNG::create
ItemStorageController::postSave protected function Overrides Drupal\Core\Entity\DataBaseStorageController::postSave(). Overrides DatabaseStorageController::postSave
ItemStorageController::preDelete protected function Overrides Drupal\Core\Entity\DataBaseStorageController::preDelete(). Overrides DatabaseStorageController::preDelete