diff --git a/entityreference.module b/entityreference.module index 18b329e..ddf3c73 100644 --- a/entityreference.module +++ b/entityreference.module @@ -173,7 +173,7 @@ function _entityreference_get_behavior_handler($behavior) { * * The handler contains most of the business logic of the field. */ -function entityreference_get_selection_handler($field, $instance = NULL) { +function entityreference_get_selection_handler($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { $object_cache = drupal_static(__FUNCTION__); if (!isset($object_cache[$field['field_name']])) { @@ -182,10 +182,10 @@ function entityreference_get_selection_handler($field, $instance = NULL) { $class = ctools_plugin_load_class('entityreference', 'selection', $handler, 'class'); if (class_exists($class)) { - $object_cache[$field['field_name']] = call_user_func(array($class, 'getInstance'), $field, $instance); + $object_cache[$field['field_name']] = call_user_func(array($class, 'getInstance'), $field, $instance, $entity_type, $entity); } else { - $object_cache[$field['field_name']] = EntityReference_SelectionHandler_Broken::getInstance($field, $instance); + $object_cache[$field['field_name']] = EntityReference_SelectionHandler_Broken::getInstance($field, $instance, $entity_type, $entity); } } @@ -627,8 +627,8 @@ function entityreference_field_widget_settings_form($field, $instance) { /** * Implements hook_options_list(). */ -function entityreference_options_list($field, $instance = NULL) { - return entityreference_get_selection_handler($field, $instance)->getReferencableEntities(); +function entityreference_options_list($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { + return entityreference_get_selection_handler($field, $instance, $entity_type, $entity)->getReferencableEntities(); } /** diff --git a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php index 0d24580..775781c 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php @@ -11,26 +11,28 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select /** * Implements EntityReferenceHandler::getInstance(). */ - public static function getInstance($field, $instance) { - $entity_type = $field['settings']['target_type']; + public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { + $target_entity_type = $field['settings']['target_type']; // Check if the entity type does exist and has a base table. - $entity_info = entity_get_info($entity_type); + $entity_info = entity_get_info($target_entity_type); if (empty($entity_info['base table'])) { return EntityReference_SelectionHandler_Broken::getInstance($field, $instance); } - if (class_exists($class_name = 'EntityReference_SelectionHandler_Generic_' . $entity_type)) { - return new $class_name($field, $instance); + if (class_exists($class_name = 'EntityReference_SelectionHandler_Generic_' . $target_entity_type)) { + return new $class_name($field, $instance, $entity_type, $entity); } else { - return new EntityReference_SelectionHandler_Generic($field, $instance); + return new EntityReference_SelectionHandler_Generic($field, $instance, $entity_type, $entity); } } - protected function __construct($field, $instance) { + protected function __construct($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { $this->field = $field; $this->instance = $instance; + $this->entity_type = $entity_type; + $this->entity = $entity; } /** diff --git a/plugins/selection/abstract.inc b/plugins/selection/abstract.inc index 75743e4..6a420e7 100644 --- a/plugins/selection/abstract.inc +++ b/plugins/selection/abstract.inc @@ -14,7 +14,7 @@ interface EntityReference_SelectionHandler { * A field datastructure. * @return EntityReferenceHandler */ - public static function getInstance($field, $instance); + public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL); /** * Return a list of referencable entities. @@ -54,8 +54,8 @@ interface EntityReference_SelectionHandler { * A null implementation of EntityReference_SelectionHandler. */ class EntityReference_SelectionHandler_Broken implements EntityReference_SelectionHandler { - public static function getInstance($field, $instance) { - return new EntityReference_SelectionHandler_Broken($field, $instance); + public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { + return new EntityReference_SelectionHandler_Broken($field, $instance, $entity_type, $entity); } protected function __construct($field, $instance) {