class FlexiformController in Flexiform 7
The Controller for FlexiformSubmission entities
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
- class \EntityAPIControllerExportable
- class \FlexiformController
- class \EntityAPIControllerExportable
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
Expanded class hierarchy of FlexiformController
1 string reference to 'FlexiformController'
- flexiform_entity_info in ./
flexiform.module - Implement hook_entity_info().
File
- ./
flexiform.entity.inc, line 108 - flexiform.entity.inc
View source
class FlexiformController extends EntityAPIControllerExportable {
public function __construct($entityType) {
parent::__construct($entityType);
}
/**
* Create a flexiform - we first set up the values that are specific
* to our flexiform schema but then also go through the EntityAPIController
* function.
*
* @param $type
* The machine-readable type of the flexiform_submission.
*
* @return
* A flexiform object with all default fields initialized.
*/
public function create(array $values = array()) {
// Add values that are specific to our FlexiformSubmission
$values += array(
'id' => '',
'is_new' => TRUE,
);
$flexiform = parent::create($values);
return $flexiform;
}
/**
* Overrides EntityAPIController::save().
*/
public function save($flexiform, DatabaseTransaction $transaction = NULL) {
$return = parent::save($flexiform);
$this
->storeDisplays($flexiform);
$this
->storeTags($flexiform);
return $return;
}
/**
* Overrides EntityAPIController::invoke().
*/
public function invoke($hook, $entity) {
parent::invoke($hook, $entity);
if ($hook == 'insert' || $hook == 'update') {
// Get hold of the display info.
$display_info = flexiform_display_info();
// Check for any displays implementing hook_menu.
foreach ($entity->displays as $id => $display) {
if (method_exists($display_info[$id]['class'], 'hook_menu')) {
if ($hook == 'update') {
// If the config has changed continue.
if (isset($entity->original->displays[$id]) && $display == $entity->original->displays[$id]) {
continue;
}
}
// Mark the menu to be rebuilt.
variable_set('menu_rebuild_needed', TRUE);
break;
}
}
}
}
/**
* Overrides EntityAPIController::attachLoad().
*/
public function attachLoad(&$queried_entities, $revision_id = FALSE) {
$ids = array_keys($queried_entities);
$tags = array();
$result = db_select('flexiform_tags')
->fields('flexiform_tags', array(
'id',
'tag',
))
->condition('id', $ids, 'IN')
->execute();
foreach ($result as $row) {
$tags[$row->id][] = $row->tag;
}
foreach ($queried_entities as $entity_id => &$entity) {
$entity->tags = !empty($tags[$entity_id]) ? $tags[$entity_id] : array();
}
}
/**
* Store the tags associated with a given flexiform.
*/
protected function storeTags($flexiform) {
db_delete('flexiform_tags')
->condition('id', $flexiform->id)
->execute();
if (!empty($flexiform->tags)) {
foreach ($flexiform->tags as $tag) {
db_insert('flexiform_tags')
->fields(array(
'id',
'tag',
), array(
$flexiform->id,
$tag,
))
->execute();
}
}
}
/**
* Store the displays associated with a given flexiform.
*/
protected function storeDisplays($flexiform) {
db_delete('flexiform_display')
->condition('form', $flexiform->form)
->execute();
if (!empty($flexiform->displays)) {
$query = db_insert('flexiform_display');
$query
->fields(array(
'id',
'form',
'display',
));
foreach ($flexiform->displays as $key => $display) {
if (($display = $flexiform
->getDisplay($key)) && $display
->isEnabled()) {
$query
->values(array(
'id' => $flexiform->id,
'form' => $flexiform->form,
'display' => $key,
));
}
}
$query
->execute();
}
}
/**
* {@inheritdoc}
*/
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id);
$query_conditions =& $query
->conditions();
foreach ($query_conditions as &$condition) {
// One entry in $query_conditions is a string with key '#conjunction'.
// @see QueryConditionInterface::conditions().
if (is_array($condition)) {
// Support using 'tags' => array('tag1', 'tag2') as condition.
if ($condition['field'] == 'base.tags') {
$query
->join('flexiform_tags', 'ft', 'base.id = ft.id');
$condition['field'] = 'ft.tag';
}
}
}
return $query;
}
/**
* {@inheritdoc}
*/
public function delete($ids, DatabaseTransaction $transaction = NULL) {
parent::delete($ids, $transaction);
db_delete('flexiform_tags')
->condition('id', $ids)
->execute();
db_delete('flexiform_display')
->condition('id', $ids)
->execute();
}
/**
* Get flexiforms with a given display(s)
*/
public function loadWithDisplay($display) {
$query = db_select('flexiform_display');
$query
->addField('flexiform_display', 'form');
$query
->condition('display', $display);
$query
->groupBy('form');
$names = $query
->execute()
->fetchCol();
return !empty($names) ? entity_load('flexiform', $names) : array();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalDefaultEntityController:: |
protected | property | Whether this entity type should use the static cache. | |
DrupalDefaultEntityController:: |
protected | property | Static cache of entities, keyed by entity ID. | |
DrupalDefaultEntityController:: |
protected | property | Array of information about the entity. | |
DrupalDefaultEntityController:: |
protected | property | Entity type for this controller instance. | |
DrupalDefaultEntityController:: |
protected | property | Additional arguments to pass to hook_TYPE_load(). | |
DrupalDefaultEntityController:: |
protected | property | Name of the entity's ID field in the entity database table. | |
DrupalDefaultEntityController:: |
protected | property | Name of entity's revision database table field, if it supports revisions. | |
DrupalDefaultEntityController:: |
protected | property | The table that stores revisions, if the entity supports revisions. | |
DrupalDefaultEntityController:: |
protected | function | Ensures integer entity IDs are valid. | |
DrupalDefaultEntityController:: |
protected | function | Callback for array_filter that removes non-integer IDs. | |
EntityAPIController:: |
protected | property | ||
EntityAPIController:: |
protected | property | ||
EntityAPIController:: |
protected | property | ||
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
EntityAPIController:: |
public | function |
Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface:: |
|
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
EntityAPIController:: |
public | function | Builds and executes the query for loading. | |
EntityAPIController:: |
protected | function | Renders a single entity property. | |
EntityAPIController:: |
protected | function | Saves an entity revision. | |
EntityAPIControllerExportable:: |
protected | property | ||
EntityAPIControllerExportable:: |
protected | property | ||
EntityAPIControllerExportable:: |
protected | function | ||
EntityAPIControllerExportable:: |
protected | function |
Overridden. Overrides DrupalDefaultEntityController:: |
|
EntityAPIControllerExportable:: |
protected | function | Like cacheGet() but keyed by name. | |
EntityAPIControllerExportable:: |
protected | function |
Overridden. Overrides DrupalDefaultEntityController:: |
|
EntityAPIControllerExportable:: |
public | function |
Overridden. Overrides EntityAPIController:: |
|
EntityAPIControllerExportable:: |
public | function |
Overridden to support passing numeric ids as well as names as $ids. Overrides EntityAPIController:: |
|
EntityAPIControllerExportable:: |
public | function |
Overrides DrupalDefaultEntityController::resetCache(). Overrides EntityAPIController:: |
|
EntityAPIControllerExportable:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIController:: |
|
FlexiformController:: |
public | function |
Overrides EntityAPIController::attachLoad(). Overrides EntityAPIControllerExportable:: |
|
FlexiformController:: |
protected | function |
Support loading by name key. Overrides EntityAPIControllerExportable:: |
|
FlexiformController:: |
public | function |
Create a flexiform - we first set up the values that are specific
to our flexiform schema but then also go through the EntityAPIController
function. Overrides EntityAPIController:: |
|
FlexiformController:: |
public | function |
Overridden to care about reverted entities. Overrides EntityAPIControllerExportable:: |
|
FlexiformController:: |
public | function |
Overrides EntityAPIController::invoke(). Overrides EntityAPIControllerExportable:: |
|
FlexiformController:: |
public | function | Get flexiforms with a given display(s) | |
FlexiformController:: |
public | function |
Overrides EntityAPIController::save(). Overrides EntityAPIControllerExportable:: |
|
FlexiformController:: |
protected | function | Store the displays associated with a given flexiform. | |
FlexiformController:: |
protected | function | Store the tags associated with a given flexiform. | |
FlexiformController:: |
public | function |
Overridden. Overrides EntityAPIControllerExportable:: |