You are here

cacheflush_entity.module in CacheFlush 8

Same filename and directory in other branches
  1. 7.3 modules/cacheflush_entity/cacheflush_entity.module

Cacheflush Entity API.

File

modules/cacheflush_entity/cacheflush_entity.module
View source
<?php

/**
 * @file
 * Cacheflush Entity API.
 */

/**
 * Constructs a new entity object, without permanently saving it.
 *
 * @param array $values
 *   Values of the entity to be created.
 *
 * @return object
 *   New cacheflush entity.
 *
 * @throws \Exception
 *   Throws exception if exists.
 */
function cacheflush_create(array $values = []) {
  return \Drupal::entityTypeManager()
    ->getStorage('cacheflush')
    ->create($values);
}

/**
 * Loads cacheflush entity by ID.
 *
 * @param mixed $id
 *   The entity ID to be loaded.
 *
 * @return null||\Drupal\Core\Entity\EntityInterface
 *   The entity object or NULL if there is no entity with the given ID.
 *
 * @throws \Exception
 *   Throws exception if exists.
 */
function cacheflush_load($id) {
  return \Drupal::entityTypeManager()
    ->getStorage('cacheflush')
    ->load($id);
}

/**
 * Loads multiple cacheflush entities from the database.
 *
 * @param array $ids
 *   (optional) An array of entity IDs. If omitted, all entities are loaded.
 *
 * @return null||array\Drupal\Core\Entity\EntityInterface
 *   An array of entity objects indexed by their IDs.
 *   Returns an empty array if no matching entities are found.
 *
 * @throws \Exception
 *   Throws exception if exists.
 */
function cacheflush_load_multiple(array $ids = NULL) {
  return \Drupal::entityTypeManager()
    ->getStorage('cacheflush')
    ->loadMultiple($ids);
}

/**
 * Load entities by their property values.
 *
 * @param array $values
 *   An associative array where the keys are the property names and the
 *   values are the values those properties must have.
 *
 * @return null||array\Drupal\Core\Entity\EntityInterface
 *   An array of entity objects indexed by their ids.
 *
 * @throws \Exception
 *   Throws exception if exists.
 */
function cacheflush_load_multiple_by_properties(array $values = []) {
  return \Drupal::entityTypeManager()
    ->getStorage('cacheflush')
    ->loadByProperties($values);
}

/**
 * Deletes a single entity by ID.
 *
 * @param mixed $id
 *   The ID of entity to be deleted.
 *
 * @throws \Exception
 *   Throws exception if exists.
 */
function cacheflush_delete($id) {
  $controller = \Drupal::entityTypeManager()
    ->getStorage('cacheflush');
  $entities = $controller
    ->load($id);
  $entities
    ->delete();
}

/**
 * Deletes all entities from ID list.
 *
 * @param array $ids
 *   The list of entity IDs.
 *
 * @throws \Exception
 *   Throws exception if exists.
 */
function cacheflush_delete_multiple(array $ids) {
  $controller = \Drupal::entityTypeManager()
    ->getStorage('cacheflush');
  $entities = $controller
    ->loadMultiple($ids);
  $controller
    ->delete($entities);
}

Functions

Namesort descending Description
cacheflush_create Constructs a new entity object, without permanently saving it.
cacheflush_delete Deletes a single entity by ID.
cacheflush_delete_multiple Deletes all entities from ID list.
cacheflush_load Loads cacheflush entity by ID.
cacheflush_load_multiple Loads multiple cacheflush entities from the database.
cacheflush_load_multiple_by_properties Load entities by their property values.