1 EntityReferenceSelectionHandlerGeneric.inc public static EntityReferenceSelectionHandlerGeneric::getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL)

Implements EntityReferenceHandler::getInstance().

Overrides EntityReferenceSelectionHandlerInterface::getInstance

File

core/modules/entityreference/plugins/selection/EntityReferenceSelectionHandlerGeneric.inc, line 28
Generic Entity handler.

Class

EntityReferenceSelectionHandlerGeneric
@file Generic Entity handler.

Code

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($target_entity_type);
  if (empty($entity_info['base table'])) {
    // Make sure the EntityReferenceSelectionHandlerBroken class is available.
    include_once (dirname(__FILE__) . '/EntityReferenceSelectionHandler.inc');
    return EntityReferenceSelectionHandlerBroken::getInstance($field, $instance);
  }

  if (class_exists($class_name = 'EntityReferenceSelectionHandlerGeneric_' . $target_entity_type)) {
    return new $class_name($field, $instance, $entity_type, $entity);
  }
  else {
    return new EntityReferenceSelectionHandlerGeneric($field, $instance, $entity_type, $entity);
  }
}