public static function FeedImport::getEntityInfo in Feed Import 7.3
Same name and namespace in other branches
- 7 feed_import.inc.php \FeedImport::getEntityInfo()
- 7.2 feed_import.inc.php \FeedImport::getEntityInfo()
Gets info about an entity. This info is cached.
Parameters
string $entity_name The entity name:
Return value
object An object that describes entity
6 calls to FeedImport::getEntityInfo()
- FeedImport::deleteExpired in feed_import_base/
inc/ feed_import.inc - Delete all expired items.
- FeedImport::setProcessorSettings in feed_import_base/
inc/ feed_import.inc - Sets processor settings.
- feed_import_base_entity_delete in feed_import_base/
feed_import_base.module - Implements hook_entity_delete().
- feed_import_fields_form in ./
feed_import.module - Fields edit form
- feed_import_fields_form_submit in ./
feed_import.module - Edit fields form submit
File
- feed_import_base/
inc/ feed_import.inc, line 34 - This file contains Feed Import helpers.
Class
- FeedImport
- This class provides helper functions for feed import.
Code
public static function getEntityInfo($entity_name) {
if (empty($entity_name)) {
return FALSE;
}
elseif (isset(static::$entityInfo[$entity_name])) {
return static::$entityInfo[$entity_name];
}
if (!($entity = entity_get_info($entity_name))) {
return FALSE;
}
// Set main entity info.
$info = (object) array(
'name' => $entity_name,
'idKey' => isset($entity['entity keys']['id']) ? $entity['entity keys']['id'] : NULL,
'langKey' => isset($entity['entity keys']['language']) ? $entity['entity keys']['language'] : 'language',
'bundleKey' => isset($entity['entity keys']['bundle']) ? $entity['entity keys']['bundle'] : NULL,
'createCallback' => isset($entity['creation callback']) ? $entity['creation callback'] : NULL,
'saveCallback' => isset($entity['save callback']) ? $entity['save callback'] : NULL,
'deleteCallback' => isset($entity['deletion callback']) ? $entity['deletion callback'] : NULL,
'controller' => entity_get_controller($entity_name),
'properties' => array(),
'fields' => array(),
);
if ($info->controller) {
$info->controller->canCreate = method_exists($info->controller, 'create');
$info->controller->canSave = method_exists($info->controller, 'save');
$info->controller->canDelete = method_exists($info->controller, 'delete');
$info->controller->canResetCache = method_exists($info->controller, 'resetCache');
}
else {
$info->controller = (object) array(
'canCreate' => FALSE,
'canSave' => FALSE,
'canDelete' => FALSE,
'canResetCache' => FALSE,
);
}
if (!$info->saveCallback && function_exists($entity_name . '_save')) {
$info->saveCallback = $entity_name . '_save';
}
if (!$info->deleteCallback && function_exists($entity_name . '_delete')) {
$info->deleteCallback = $entity_name . '_delete';
}
// Get fields info.
if ($fieldlist = field_info_instances($entity_name)) {
foreach ($fieldlist as &$fields) {
foreach ($fields as &$field) {
if (!empty($field['deleted']) || isset($info->fields[$field['field_name']])) {
continue;
}
$field_info = field_info_field($field['field_name']);
$info->fields[$field['field_name']] = array(
'name' => $field['field_name'],
'column' => key($field_info['columns']),
'columns' => array_keys($field_info['columns']),
'cardinality' => $field_info['cardinality'],
'type' => $field_info['type'],
'module' => $field_info['module'],
);
}
}
}
if (function_exists('entity_get_property_info')) {
// Get properties info.
$prop_info = entity_get_property_info($entity_name);
if (isset($prop_info['properties'])) {
foreach ($prop_info['properties'] as $pname => $pval) {
if (isset($pval['schema field'])) {
$pval = $pval['schema field'];
}
else {
$pval = $pname;
}
if (!isset($info->fields[$pval])) {
$info->properties[] = $pval;
}
}
$info->properties = array_unique($info->properties);
}
}
elseif (isset($entity['schema_fields_sql']['base table'])) {
$info->properties = array_diff($entity['schema_fields_sql']['base table'], array_keys($info->fields));
}
return static::$entityInfo[$entity_name] = $info;
}