@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class EntityReferenceBehavior_ViewsFilterSelect extends EntityReference_BehaviorHandler_Abstract {
|
||||
|
||||
public function views_data_alter(&$data, $field) {
|
||||
$entity_info = entity_get_info($field['settings']['target_type']);
|
||||
$field_name = $field['field_name'] . '_target_id';
|
||||
foreach ($data as $table_name => &$table_data) {
|
||||
if (isset($table_data[$field_name])) {
|
||||
// Set the entity id filter to use the in_operator handler with our
|
||||
// own callback to return the values.
|
||||
$table_data[$field_name]['filter']['handler'] = 'views_handler_filter_in_operator';
|
||||
$table_data[$field_name]['filter']['options callback'] = 'entityreference_views_handler_options_list';
|
||||
$table_data[$field_name]['filter']['options arguments'] = array($field['field_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
187
plugins/behavior/abstract.inc
Normal file
187
plugins/behavior/abstract.inc
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Additional behaviors for a Entity Reference field.
|
||||
*
|
||||
* Implementations that wish to provide an implementation of this should
|
||||
* register it using CTools' plugin system.
|
||||
*/
|
||||
interface EntityReference_BehaviorHandler {
|
||||
|
||||
/**
|
||||
* Constructor for the behavior.
|
||||
*
|
||||
* @param $behavior
|
||||
* The name of the behavior plugin.
|
||||
*/
|
||||
public function __construct($behavior);
|
||||
|
||||
/**
|
||||
* Alter the field schema.
|
||||
*
|
||||
* @see hook_field_schema()
|
||||
*/
|
||||
public function schema_alter(&$schema, $field);
|
||||
|
||||
/**
|
||||
* Alter the properties information of a field instance.
|
||||
*
|
||||
* @see entity_hook_field_info()
|
||||
*/
|
||||
public function property_info_alter(&$info, $entity_type, $field, $instance, $field_type);
|
||||
|
||||
/**
|
||||
* Alter the views data of a field.
|
||||
*
|
||||
* @see entityreference_field_views_data()
|
||||
*/
|
||||
public function views_data_alter(&$data, $field);
|
||||
|
||||
/**
|
||||
* Act on loading entity reference fields of entities.
|
||||
*
|
||||
* @see hook_field_load()
|
||||
*/
|
||||
public function load($entity_type, $entities, $field, $instances, $langcode, &$items);
|
||||
|
||||
/**
|
||||
* Alter the empty status of a field item.
|
||||
*
|
||||
* @see hook_field_is_empty()
|
||||
*/
|
||||
public function is_empty_alter(&$empty, $item, $field);
|
||||
|
||||
/**
|
||||
* Act on validating an entity reference field.
|
||||
*
|
||||
* @see hook_field_validate()
|
||||
*/
|
||||
public function validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors);
|
||||
|
||||
/**
|
||||
* Act on presaving an entity reference field.
|
||||
*
|
||||
* @see hook_field_presave()
|
||||
*/
|
||||
public function presave($entity_type, $entity, $field, $instance, $langcode, &$items);
|
||||
|
||||
/**
|
||||
* Act before inserting an entity reference field.
|
||||
*
|
||||
* @see hook_field_insert()
|
||||
*/
|
||||
public function insert($entity_type, $entity, $field, $instance, $langcode, &$items);
|
||||
|
||||
/**
|
||||
* Act after inserting an entity reference field.
|
||||
*
|
||||
* @see hook_field_attach_insert()
|
||||
*/
|
||||
public function postInsert($entity_type, $entity, $field, $instance);
|
||||
|
||||
/**
|
||||
* Act before updating an entity reference field.
|
||||
*
|
||||
* @see hook_field_update()
|
||||
*/
|
||||
public function update($entity_type, $entity, $field, $instance, $langcode, &$items);
|
||||
|
||||
/**
|
||||
* Act after updating an entity reference field.
|
||||
*
|
||||
* @see hook_field_attach_update()
|
||||
*/
|
||||
public function postUpdate($entity_type, $entity, $field, $instance);
|
||||
|
||||
/**
|
||||
* Act before deleting an entity with an entity reference field.
|
||||
*
|
||||
* @see hook_field_delete()
|
||||
*/
|
||||
public function delete($entity_type, $entity, $field, $instance, $langcode, &$items);
|
||||
|
||||
/**
|
||||
* Act after deleting an entity with an entity reference field.
|
||||
*
|
||||
* @see hook_field_attach_delete()
|
||||
*/
|
||||
public function postDelete($entity_type, $entity, $field, $instance);
|
||||
|
||||
/**
|
||||
* Generate a settings form for this handler.
|
||||
*/
|
||||
public function settingsForm($field, $instance);
|
||||
|
||||
/**
|
||||
* Determine if handler should appear.
|
||||
*/
|
||||
public function access($field, $instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* An abstract implementation of EntityReference_BehaviorHandler.
|
||||
*/
|
||||
abstract class EntityReference_BehaviorHandler_Abstract implements EntityReference_BehaviorHandler {
|
||||
|
||||
/**
|
||||
* The name of the behavior plugin.
|
||||
*/
|
||||
protected $behavior;
|
||||
|
||||
/**
|
||||
* The plugin definition.
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
public function __construct($behavior) {
|
||||
$this->behavior = $behavior;
|
||||
|
||||
ctools_include('plugins');
|
||||
$plugin = ctools_get_plugins('entityreference', 'behavior', $behavior);
|
||||
$this->plugin = $plugin;
|
||||
}
|
||||
|
||||
public function schema_alter(&$schema, $field) {}
|
||||
|
||||
public function property_info_alter(&$info, $entity_type, $field, $instance, $field_type) {}
|
||||
|
||||
public function views_data_alter(&$data, $field) {}
|
||||
|
||||
public function load($entity_type, $entities, $field, $instances, $langcode, &$items) {}
|
||||
|
||||
public function is_empty_alter(&$empty, $item, $field) {}
|
||||
|
||||
public function validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {}
|
||||
|
||||
public function presave($entity_type, $entity, $field, $instance, $langcode, &$items) {}
|
||||
|
||||
public function insert($entity_type, $entity, $field, $instance, $langcode, &$items) {}
|
||||
|
||||
public function postInsert($entity_type, $entity, $field, $instance) {}
|
||||
|
||||
public function update($entity_type, $entity, $field, $instance, $langcode, &$items) {}
|
||||
|
||||
public function postUpdate($entity_type, $entity, $field, $instance) {}
|
||||
|
||||
public function delete($entity_type, $entity, $field, $instance, $langcode, &$items) {}
|
||||
|
||||
public function postDelete($entity_type, $entity, $field, $instance) {}
|
||||
|
||||
public function settingsForm($field, $instance) {}
|
||||
|
||||
public function access($field, $instance) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A broken implementation of EntityReference_BehaviorHandler.
|
||||
*/
|
||||
class EntityReference_BehaviorHandler_Broken extends EntityReference_BehaviorHandler_Abstract {
|
||||
public function settingsForm($field, $instance) {
|
||||
$form['behavior_handler'] = array(
|
||||
'#markup' => t('The selected behavior handler is broken.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
}
|
10
plugins/behavior/views-select-list.inc
Normal file
10
plugins/behavior/views-select-list.inc
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
if (module_exists('views')) {
|
||||
$plugin = array(
|
||||
'title' => t('Render Views filters as select list'),
|
||||
'description' => t('Provides a select list for Views filters on this field. This should not be used when there are over 100 entities, as it might cause an out of memory error.'),
|
||||
'class' => 'EntityReferenceBehavior_ViewsFilterSelect',
|
||||
'behavior type' => 'field',
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user