12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574 |
- <?php
- module_load_include('inc', 'entity', 'modules/callbacks');
- module_load_include('inc', 'entity', 'includes/entity.property');
- define('ENTITY_CUSTOM', 0x01);
- define('ENTITY_IN_DB', 0x01);
- define('ENTITY_IN_CODE', 0x02);
- define('ENTITY_OVERRIDDEN', 0x03);
- define('ENTITY_FIXED', 0x04 | 0x02);
- function entity_type_supports($entity_type, $op) {
- $info = entity_get_info($entity_type);
- $keys = array(
- 'view' => 'view callback',
- 'create' => 'creation callback',
- 'delete' => 'deletion callback',
- 'revision delete' => 'revision deletion callback',
- 'save' => 'save callback',
- 'access' => 'access callback',
- 'form' => 'form callback'
- );
- if (isset($info[$keys[$op]])) {
- return TRUE;
- }
- if ($op == 'revision delete') {
- return in_array('EntityAPIControllerInterface', class_implements($info['controller class']));
- }
- if ($op == 'form') {
- return (bool) entity_ui_controller($entity_type);
- }
- if ($op != 'access') {
- return in_array('EntityAPIControllerInterface', class_implements($info['controller class']));
- }
- return FALSE;
- }
- function entity_object_load($entity_id, $entity_type) {
- $entities = entity_load($entity_type, array($entity_id));
- return reset($entities);
- }
- function entity_ui_bundle_add_page($entity_type) {
-
- module_load_include('inc', 'entity', 'includes/entity.ui');
- drupal_set_title(entity_ui_get_action_title('add', $entity_type));
-
- $info = entity_get_info($entity_type);
- $items = array();
- foreach ($info['bundles'] as $bundle_name => $bundle_info) {
-
- $dummy_entity = entity_create($entity_type, array(
- $info['entity keys']['bundle'] => $bundle_name,
- ));
-
-
- if (entity_access('create', $entity_type, $dummy_entity, $account = NULL)) {
- $add_path = $info['admin ui']['path'] . '/add/' . $bundle_name;
- $items[] = l(t('Add @label', array('@label' => $bundle_info['label'])), $add_path);
- }
- }
- return theme('item_list', array('items' => $items));
- }
- function entity_ui_get_bundle_add_form($entity_type, $bundle_name) {
- $info = entity_get_info($entity_type);
- $bundle_key = $info['entity keys']['bundle'];
-
- $values = array(
- $bundle_key => $bundle_name,
- );
- $entity = entity_create($entity_type, $values);
- return entity_ui_get_form($entity_type, $entity, 'add');
- }
- function entity_ui_entity_page_view($entity) {
- module_load_include('inc', 'entity', 'includes/entity.ui');
- return $entity->view('full', NULL, TRUE);
- }
- function entity_ui_get_page_title($op, $entity_type, $entity = NULL) {
- if (isset($entity)) {
- module_load_include('inc', 'entity', 'includes/entity.ui');
- $label = entity_label($entity_type, $entity);
- list(, , $bundle) = entity_extract_ids($entity_type, $entity);
- }
- else {
- $info = entity_get_info($entity_type);
- $label = $info['label'];
- $bundle = NULL;
- }
- switch ($op) {
- case 'view':
- return $label;
- case 'edit':
- return t('Edit @label', array('@label' => $label));
- case 'clone':
- return t('Clone @label', array('@label' => $label));
- case 'revert':
- return t('Revert @label', array('@label' => $label));
- case 'delete':
- return t('Delete @label', array('@label' => $label));
- case 'export':
- return t('Export @label', array('@label' => $label));
- }
- return entity_ui_get_action_title($op, $entity_type, $bundle);
- }
- function entity_load_single($entity_type, $id) {
- $entities = entity_load($entity_type, array($id));
- return reset($entities);
- }
- function entity_load_multiple_by_name($entity_type, $names = FALSE, $conditions = array()) {
- $entities = entity_load($entity_type, $names, $conditions);
- $info = entity_get_info($entity_type);
- if (!isset($info['entity keys']['name'])) {
- return $entities;
- }
- return entity_key_array_by_property($entities, $info['entity keys']['name']);
- }
- function entity_save($entity_type, $entity) {
- $info = entity_get_info($entity_type);
- if (method_exists($entity, 'save')) {
- return $entity->save();
- }
- elseif (isset($info['save callback'])) {
- $info['save callback']($entity);
- }
- elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- return entity_get_controller($entity_type)->save($entity);
- }
- else {
- return FALSE;
- }
- }
- function entity_delete($entity_type, $id) {
- return entity_delete_multiple($entity_type, array($id));
- }
- function entity_delete_multiple($entity_type, $ids) {
- $info = entity_get_info($entity_type);
- if (isset($info['deletion callback'])) {
- foreach ($ids as $id) {
- $info['deletion callback']($id);
- }
- }
- elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- entity_get_controller($entity_type)->delete($ids);
- }
- else {
- return FALSE;
- }
- }
- function entity_revision_load($entity_type, $revision_id) {
- $info = entity_get_info($entity_type);
- if (!empty($info['entity keys']['revision'])) {
- $entity_revisions = entity_load($entity_type, FALSE, array($info['entity keys']['revision'] => $revision_id));
- return reset($entity_revisions);
- }
- return FALSE;
- }
- function entity_revision_delete($entity_type, $revision_id) {
- $info = entity_get_info($entity_type);
- if (isset($info['revision deletion callback'])) {
- return $info['revision deletion callback']($revision_id, $entity_type);
- }
- elseif (in_array('EntityAPIControllerRevisionableInterface', class_implements($info['controller class']))) {
- return entity_get_controller($entity_type)->deleteRevision($revision_id);
- }
- return FALSE;
- }
- function entity_revision_is_default($entity_type, $entity) {
- $info = entity_get_info($entity_type);
- if (empty($info['entity keys']['revision'])) {
- return TRUE;
- }
-
- if (!empty($entity->is_new) || empty($entity->{$info['entity keys']['id']})) {
- return TRUE;
- }
- if (in_array('EntityAPIControllerRevisionableInterface', class_implements($info['controller class']))) {
- $key = !empty($info['entity keys']['default revision']) ? $info['entity keys']['default revision'] : 'default_revision';
- return !empty($entity->$key);
- }
- else {
-
-
- $default = entity_load_single($entity_type, $entity->{$info['entity keys']['id']});
- return $default->{$info['entity keys']['revision']} == $entity->{$info['entity keys']['revision']};
- }
- }
- function entity_revision_set_default($entity_type, $entity) {
- $info = entity_get_info($entity_type);
- if (!empty($info['entity keys']['revision'])) {
- $key = !empty($info['entity keys']['default revision']) ? $info['entity keys']['default revision'] : 'default_revision';
- $entity->$key = TRUE;
- }
- }
- function entity_create($entity_type, array $values) {
- $info = entity_get_info($entity_type);
- if (isset($info['creation callback'])) {
- return $info['creation callback']($values, $entity_type);
- }
- elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- return entity_get_controller($entity_type)->create($values);
- }
- return FALSE;
- }
- function entity_export($entity_type, $entity, $prefix = '') {
- if (method_exists($entity, 'export')) {
- return $entity->export($prefix);
- }
- $info = entity_get_info($entity_type);
- if (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- return entity_get_controller($entity_type)->export($entity, $prefix);
- }
- }
- function entity_import($entity_type, $export) {
- $info = entity_get_info($entity_type);
- if (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- return entity_get_controller($entity_type)->import($export);
- }
- }
- function entity_type_is_fieldable($entity_type) {
- $info = entity_get_info($entity_type);
- return !empty($info['fieldable']);
- }
- function entity_build_content($entity_type, $entity, $view_mode = 'full', $langcode = NULL) {
- $info = entity_get_info($entity_type);
- if (method_exists($entity, 'buildContent')) {
- return $entity->buildContent($view_mode, $langcode);
- }
- elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- return entity_get_controller($entity_type)->buildContent($entity, $view_mode, $langcode);
- }
- }
- function entity_id($entity_type, $entity) {
- if (method_exists($entity, 'identifier')) {
- return $entity->identifier();
- }
- $info = entity_get_info($entity_type);
- $key = isset($info['entity keys']['name']) ? $info['entity keys']['name'] : $info['entity keys']['id'];
- return isset($entity->$key) ? $entity->$key : NULL;
- }
- function entity_view($entity_type, $entities, $view_mode = 'full', $langcode = NULL, $page = NULL) {
- $info = entity_get_info($entity_type);
- if (isset($info['view callback'])) {
- $entities = entity_key_array_by_property($entities, $info['entity keys']['id']);
- return $info['view callback']($entities, $view_mode, $langcode, $entity_type);
- }
- elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- return entity_get_controller($entity_type)->view($entities, $view_mode, $langcode, $page);
- }
- return FALSE;
- }
- function entity_access($op, $entity_type, $entity = NULL, $account = NULL) {
- if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) {
- return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type);
- }
- }
- function entity_form($entity_type, $entity) {
- $info = entity_get_info($entity_type);
- if (isset($info['form callback'])) {
- return $info['form callback']($entity, $entity_type);
- }
-
-
- elseif (entity_ui_controller($entity_type)) {
- return entity_metadata_form_entity_ui($entity, $entity_type);
- }
- return FALSE;
- }
- function entity_key_array_by_property(array $entities, $property) {
- $ret = array();
- foreach ($entities as $entity) {
- $key = isset($entity->$property) ? $entity->$property : NULL;
- $ret[$key] = $entity;
- }
- return $ret;
- }
- function entity_crud_get_info() {
- $types = array();
- foreach (entity_get_info() as $type => $info) {
- if (isset($info['controller class']) && in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- $types[$type] = $info;
- }
- }
- return $types;
- }
- function entity_has_status($entity_type, $entity, $status) {
- $info = entity_get_info($entity_type);
- $status_key = empty($info['entity keys']['status']) ? 'status' : $info['entity keys']['status'];
- return isset($entity->{$status_key}) && ($entity->{$status_key} & $status) == $status;
- }
- function entity_var_export($var, $prefix = '') {
- if (is_array($var)) {
- if (empty($var)) {
- $output = 'array()';
- }
- else {
- $output = "array(\n";
- foreach ($var as $key => $value) {
- $output .= " '$key' => " . entity_var_export($value, ' ') . ",\n";
- }
- $output .= ')';
- }
- }
- elseif (is_bool($var)) {
- $output = $var ? 'TRUE' : 'FALSE';
- }
- else {
- $output = var_export($var, TRUE);
- }
- if ($prefix) {
- $output = str_replace("\n", "\n$prefix", $output);
- }
- return $output;
- }
- function entity_var_json_export($var, $prefix = '') {
- if (is_array($var) && $var) {
-
- $use_array = ($var == array_values($var));
- $output = $use_array ? "[" : "{";
- foreach ($var as $key => $value) {
- if ($use_array) {
- $values[] = entity_var_json_export($value, ' ');
- }
- else {
- $values[] = entity_var_json_export((string) $key, ' ') . ' : ' . entity_var_json_export($value, ' ');
- }
- }
-
-
- if (strlen($content = implode(', ', $values)) > 70 && ($use_array || count($values) > 1)) {
- $output .= "\n " . implode(",\n ", $values) . "\n";
- }
- elseif (strpos($content, "\n") !== FALSE) {
- $output .= " " . $content . "\n";
- }
- else {
- $output .= " " . $content . ' ';
- }
- $output .= $use_array ? ']' : '}';
- }
- else {
- $output = drupal_json_encode($var);
- }
- if ($prefix) {
- $output = str_replace("\n", "\n$prefix", $output);
- }
- return $output;
- }
- function entity_defaults_rebuild($entity_types = NULL) {
- if (!isset($entity_types)) {
- $entity_types = array();
- foreach (entity_crud_get_info() as $type => $info) {
- if (!empty($info['exportable'])) {
- $entity_types[] = $type;
- }
- };
- }
- foreach ($entity_types as $type) {
- _entity_defaults_rebuild($type);
- }
- }
- function _entity_defaults_rebuild($entity_type) {
- if (lock_acquire('entity_rebuild_' . $entity_type)) {
- $info = entity_get_info($entity_type);
- $hook = isset($info['export']['default hook']) ? $info['export']['default hook'] : 'default_' . $entity_type;
- $keys = $info['entity keys'] + array('module' => 'module', 'status' => 'status', 'name' => $info['entity keys']['id']);
-
- if (!in_array($keys['status'], $info['schema_fields_sql']['base table']) || !in_array($keys['module'], $info['schema_fields_sql']['base table'])) {
- trigger_error("Missing database columns for the exportable entity $entity_type as defined by entity_exportable_schema_fields(). Update the according module and run update.php!", E_USER_WARNING);
- return;
- }
-
- $entities = array();
- foreach (module_implements($hook) as $module) {
- foreach ((array) module_invoke($module, $hook) as $name => $entity) {
- $entity->{$keys['name']} = $name;
- $entity->{$keys['module']} = $module;
- $entities[$name] = $entity;
- }
- }
- drupal_alter($hook, $entities);
-
- $existing_defaults = entity_load_multiple_by_name($entity_type, FALSE, array($keys['status'] => array(ENTITY_OVERRIDDEN, ENTITY_IN_CODE, ENTITY_FIXED)));
- foreach ($existing_defaults as $name => $entity) {
- if (empty($entities[$name])) {
- $entity->is_rebuild = TRUE;
- if (entity_has_status($entity_type, $entity, ENTITY_OVERRIDDEN)) {
- $entity->{$keys['status']} = ENTITY_CUSTOM;
- entity_save($entity_type, $entity);
- }
- else {
- entity_delete($entity_type, $name);
- }
- unset($entity->is_rebuild);
- }
- }
-
- $existing_entities = entity_load_multiple_by_name($entity_type, array_keys($entities));
- foreach ($existing_entities as $name => $entity) {
- if (entity_has_status($entity_type, $entity, ENTITY_CUSTOM)) {
-
-
- if (!entity_has_status($entity_type, $entity, ENTITY_OVERRIDDEN)) {
- $entity->{$keys['status']} |= ENTITY_OVERRIDDEN;
- $entity->{$keys['module']} = $entities[$name]->{$keys['module']};
- $entity->is_rebuild = TRUE;
- entity_save($entity_type, $entity);
- unset($entity->is_rebuild);
- }
-
- unset($entities[$name]);
- }
- }
-
- $originals = array();
- foreach ($entities as $name => $entity) {
- if (!empty($existing_entities[$name])) {
-
- $entity->{$keys['id']} = $existing_entities[$name]->{$keys['id']};
- unset($entity->is_new);
- }
-
-
- $entity->original = !empty($existing_entities[$name]) ? $existing_entities[$name] : FALSE;
-
-
- $originals[$name] = $entity->original;
- if (!isset($entity->{$keys['status']})) {
- $entity->{$keys['status']} = ENTITY_IN_CODE;
- }
- else {
- $entity->{$keys['status']} |= ENTITY_IN_CODE;
- }
- $entity->is_rebuild = TRUE;
- entity_save($entity_type, $entity);
- unset($entity->is_rebuild);
- }
-
-
- module_invoke_all($entity_type . '_defaults_rebuild', $entities, $originals);
- lock_release('entity_rebuild_' . $entity_type);
- }
- }
- function entity_modules_installed($modules) {
- module_load_install('entity');
- entity_entitycache_installed_modules($modules);
- }
- function entity_modules_uninstalled($modules) {
- module_load_install('entity');
- entity_entitycache_uninstalled_modules($modules);
- }
- function entity_modules_enabled($modules) {
- foreach (_entity_modules_get_default_types($modules) as $type) {
- _entity_defaults_rebuild($type);
- }
- }
- function entity_modules_disabled($modules) {
- foreach (_entity_modules_get_default_types($modules) as $entity_type) {
- $info = entity_get_info($entity_type);
-
- if (isset($info['module']) && in_array($info['module'], $modules)) {
- return;
- }
- $keys = $info['entity keys'] + array('module' => 'module', 'status' => 'status', 'name' => $info['entity keys']['id']);
-
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', $entity_type, '=')
- ->propertyCondition($keys['module'], $modules, 'IN')
- ->propertyCondition($keys['status'], array(ENTITY_IN_CODE, ENTITY_FIXED), 'IN');
- $result = $query->execute();
- if (isset($result[$entity_type])) {
- $entities = entity_load($entity_type, array_keys($result[$entity_type]));
- entity_delete_multiple($entity_type, array_keys($entities));
- }
-
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', $entity_type, '=')
- ->propertyCondition($keys['module'], $modules, 'IN')
- ->propertyCondition($keys['status'], ENTITY_OVERRIDDEN, '=');
- $result = $query->execute();
- if (isset($result[$entity_type])) {
- foreach (entity_load($entity_type, array_keys($result[$entity_type])) as $name => $entity) {
- $entity->{$keys['status']} = ENTITY_CUSTOM;
- $entity->{$keys['module']} = NULL;
- entity_save($entity_type, $entity);
- }
- }
-
-
- _entity_defaults_rebuild($entity_type);
- }
- }
- function _entity_modules_get_default_types($modules) {
- $types = array();
- foreach (entity_crud_get_info() as $entity_type => $info) {
- if (!empty($info['exportable'])) {
- $hook = isset($info['export']['default hook']) ? $info['export']['default hook'] : 'default_' . $entity_type;
- foreach ($modules as $module) {
- if (module_hook($module, $hook) || module_hook($module, $hook . '_alter')) {
- $types[] = $entity_type;
- }
- }
- }
- }
- return $types;
- }
- function entity_exportable_schema_fields($module_col = 'module', $status_col = 'status') {
- return array(
- $status_col => array(
- 'type' => 'int',
- 'not null' => TRUE,
-
-
- 'default' => 0x01,
- 'size' => 'tiny',
- 'description' => 'The exportable status of the entity.',
- ),
- $module_col => array(
- 'description' => 'The name of the providing module if the entity has been defined in code.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- ),
- );
- }
- function entity_flush_caches() {
- entity_property_info_cache_clear();
-
-
-
-
-
- if (current_path() != 'admin/modules/list/confirm' && variable_get('entity_rebuild_on_flush', TRUE)) {
- entity_defaults_rebuild();
- }
-
- if (module_exists('entitycache')) {
- $tables = array();
- foreach (entity_crud_get_info() as $entity_type => $entity_info) {
- if (isset($entity_info['module']) && !empty($entity_info['entity cache'])) {
- $tables[] = 'cache_entity_' . $entity_type;
- }
- }
- return $tables;
- }
- }
- function entity_theme() {
-
-
-
-
-
- $types = array_keys(entity_crud_get_info());
- $pattern = '(' . implode('|', $types) . ')(\.|__)';
- return array(
- 'entity_status' => array(
- 'variables' => array('status' => NULL, 'html' => TRUE),
- 'file' => 'theme/entity.theme.inc',
- ),
- 'entity' => array(
- 'render element' => 'elements',
- 'template' => 'entity',
- 'pattern' => $pattern,
- 'path' => drupal_get_path('module', 'entity') . '/theme',
- 'file' => 'entity.theme.inc',
- ),
- 'entity_property' => array(
- 'render element' => 'elements',
- 'file' => 'theme/entity.theme.inc',
- ),
- 'entity_ui_overview_item' => array(
- 'variables' => array('label' => NULL, 'entity_type' => NULL, 'url' => FALSE, 'name' => FALSE),
- 'file' => 'includes/entity.ui.inc'
- ),
- );
- }
- function entity_class_label($entity) {
- return $entity->label();
- }
- function entity_class_uri($entity) {
- return $entity->uri();
- }
- function entity_file_download_access($field, $entity_type, $entity) {
- $info = entity_get_info($entity_type);
- if (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
- return entity_access('view', $entity_type, $entity);
- }
- }
- function entity_ui_controller($type = NULL) {
- $static = &drupal_static(__FUNCTION__);
- if (!isset($type)) {
-
-
- foreach (entity_get_info() as $entity_type => $info) {
- entity_ui_controller($entity_type);
- }
- return array_filter($static);
- }
- if (!isset($static[$type])) {
- $info = entity_get_info($type);
- $class = isset($info['admin ui']['controller class']) ? $info['admin ui']['controller class'] : 'EntityDefaultUIController';
- $static[$type] = (isset($info['admin ui']['path']) && $class) ? new $class($type, $info) : FALSE;
- }
- return $static[$type];
- }
- function entity_menu() {
- $items = array();
- foreach (entity_ui_controller() as $controller) {
- $items += $controller->hook_menu();
- }
- return $items;
- }
- function entity_forms($form_id, $args) {
-
-
-
- if (isset($args[0]) && is_string($args[0]) && entity_get_info($args[0])) {
- $type = $args[0];
- }
- elseif (isset($args[2]) && is_string($args[2]) && entity_get_info($args[2])) {
- $type = $args[2];
- }
- if (isset($type) && $controller = entity_ui_controller($type)) {
- return $controller->hook_forms();
- }
- }
- function entity_ui_get_form($entity_type, $entity, $op = 'edit', $form_state = array()) {
- if (isset($entity)) {
- list(, , $bundle) = entity_extract_ids($entity_type, $entity);
- }
- $form_id = (!isset($bundle) || $bundle == $entity_type) ? $entity_type . '_form' : $entity_type . '_edit_' . $bundle . '_form';
- if (!isset($entity) && $op == 'add') {
- $entity = entity_create($entity_type, array());
- }
-
-
- $form_state['wrapper_callback'] = 'entity_ui_main_form_defaults';
- $form_state['entity_type'] = $entity_type;
- form_load_include($form_state, 'inc', 'entity', 'includes/entity.ui');
-
-
- if ($op == 'clone') {
- $entity = entity_ui_clone_entity($entity_type, $entity);
- }
-
-
-
-
-
- $form_state['build_info']['args'] = array($entity, $op, $entity_type);
- return drupal_build_form($form_id, $form_state);
- }
- function entity_ui_get_action_title($op, $entity_type, $bundle_name = NULL) {
- $info = entity_get_info($entity_type);
- switch ($op) {
- case 'add':
- if (isset($bundle_name) && $bundle_name != $entity_type) {
- return t('Add @bundle_name @entity_type', array(
- '@bundle_name' => drupal_strtolower($info['bundles'][$bundle_name]['label']),
- '@entity_type' => drupal_strtolower($info['label']),
- ));
- }
- else {
- return t('Add @entity_type', array('@entity_type' => drupal_strtolower($info['label'])));
- }
- case 'import':
- return t('Import @entity_type', array('@entity_type' => drupal_strtolower($info['label'])));
- }
- }
- function entity_i18n_string($name, $default, $langcode = NULL) {
- return function_exists('i18n_string') ? i18n_string($name, $default, array('langcode' => $langcode)) : $default;
- }
- function entity_views_api() {
- return array(
- 'api' => '3.0-alpha1',
- 'path' => drupal_get_path('module', 'entity') . '/views',
- );
- }
- function entity_field_extra_fields() {
-
- $items = array();
- foreach (entity_crud_get_info() as $type => $info) {
- if (!empty($info['extra fields controller class'])) {
- $items = array_merge_recursive($items, entity_get_extra_fields_controller($type)->fieldExtraFields());
- }
- }
- return $items;
- }
- function entity_get_extra_fields_controller($type = NULL) {
- $static = &drupal_static(__FUNCTION__);
- if (!isset($static[$type])) {
- $static[$type] = FALSE;
- $info = entity_get_info($type);
- if (!empty($info['extra fields controller class'])) {
- $static[$type] = new $info['extra fields controller class']($type);
- }
- }
- return $static[$type];
- }
- function entity_metadata_wrapper($type, $data = NULL, array $info = array()) {
- if ($type == 'entity' || (($entity_info = entity_get_info()) && isset($entity_info[$type]))) {
-
-
- if ($type == 'user' && is_object($data) && $data == $GLOBALS['user']) {
- $data = $data->uid;
- }
- return new EntityDrupalWrapper($type, $data, $info);
- }
- elseif ($type == 'list' || entity_property_list_extract_type($type)) {
- return new EntityListWrapper($type, $data, $info);
- }
- elseif (isset($info['property info'])) {
- return new EntityStructureWrapper($type, $data, $info);
- }
- else {
- return new EntityValueWrapper($type, $data, $info);
- }
- }
- function entity_metadata_site_wrapper() {
- $site_info = entity_get_property_info('site');
- $info['property info'] = $site_info['properties'];
- return entity_metadata_wrapper('site', FALSE, $info);
- }
- function entity_module_implements_alter(&$implementations, $hook) {
- if ($hook == 'entity_info_alter') {
-
- $group = $implementations['entity'];
- unset($implementations['entity']);
- $implementations['entity'] = $group;
- }
- }
- function entity_entity_info_alter(&$entity_info) {
- _entity_info_add_metadata($entity_info);
-
- foreach ($entity_info as $type => $info) {
- if (!isset($info['configuration'])) {
- $entity_info[$type]['configuration'] = !empty($info['exportable']);
- }
- if (isset($info['controller class']) && in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
-
- if (!empty($info['entity cache']) && module_exists('entitycache')) {
- $entity_info[$type]['field cache'] = FALSE;
- }
- }
- }
- }
- function _entity_info_add_metadata(&$entity_info) {
-
- $entity_info['node']['plural label'] = t('Nodes');
- $entity_info['user']['plural label'] = t('Users');
- $entity_info['file']['plural label'] = t('Files');
-
- $entity_info['node']['description'] = t('Nodes represent the main site content items.');
- $entity_info['user']['description'] = t('Users who have created accounts on your site.');
- $entity_info['file']['description'] = t('Uploaded file.');
-
- $entity_info['node']['access callback'] = 'entity_metadata_no_hook_node_access';
- $entity_info['user']['access callback'] = 'entity_metadata_user_access';
-
- if (!module_exists('file_entity')) {
- $entity_info['file']['access callback'] = 'entity_metadata_file_access';
- }
-
- $entity_info['node']['creation callback'] = 'entity_metadata_create_node';
- $entity_info['node']['save callback'] = 'node_save';
- $entity_info['node']['deletion callback'] = 'node_delete';
- $entity_info['node']['revision deletion callback'] = 'node_revision_delete';
- $entity_info['user']['creation callback'] = 'entity_metadata_create_object';
- $entity_info['user']['save callback'] = 'entity_metadata_user_save';
- $entity_info['user']['deletion callback'] = 'user_delete';
- $entity_info['file']['save callback'] = 'file_save';
- $entity_info['file']['deletion callback'] = 'entity_metadata_delete_file';
-
- $entity_info['node']['form callback'] = 'entity_metadata_form_node';
- $entity_info['user']['form callback'] = 'entity_metadata_form_user';
-
- if (!isset($entity_info['file']['uri callback'])) {
- $entity_info['file']['uri callback'] = 'entity_metadata_uri_file';
- }
-
- $entity_info['node']['view callback'] = 'entity_metadata_view_node';
- $entity_info['user']['view callback'] = 'entity_metadata_view_single';
- if (module_exists('comment')) {
- $entity_info['comment']['plural label'] = t('Comments');
- $entity_info['comment']['description'] = t('Remark or note that refers to a node.');
- $entity_info['comment']['access callback'] = 'entity_metadata_comment_access';
- $entity_info['comment']['creation callback'] = 'entity_metadata_create_comment';
- $entity_info['comment']['save callback'] = 'comment_save';
- $entity_info['comment']['deletion callback'] = 'comment_delete';
- $entity_info['comment']['view callback'] = 'entity_metadata_view_comment';
- $entity_info['comment']['form callback'] = 'entity_metadata_form_comment';
- }
- if (module_exists('taxonomy')) {
- $entity_info['taxonomy_term']['plural label'] = t('Taxonomy terms');
- $entity_info['taxonomy_term']['description'] = t('Taxonomy terms are used for classifying content.');
- $entity_info['taxonomy_term']['access callback'] = 'entity_metadata_taxonomy_access';
- $entity_info['taxonomy_term']['creation callback'] = 'entity_metadata_create_object';
- $entity_info['taxonomy_term']['save callback'] = 'taxonomy_term_save';
- $entity_info['taxonomy_term']['deletion callback'] = 'taxonomy_term_delete';
- $entity_info['taxonomy_term']['view callback'] = 'entity_metadata_view_single';
- $entity_info['taxonomy_term']['form callback'] = 'entity_metadata_form_taxonomy_term';
- $entity_info['taxonomy_vocabulary']['plural label'] = t('Taxonomy vocabularies');
- $entity_info['taxonomy_vocabulary']['description'] = t('Vocabularies contain related taxonomy terms, which are used for classifying content.');
- $entity_info['taxonomy_vocabulary']['access callback'] = 'entity_metadata_taxonomy_access';
- $entity_info['taxonomy_vocabulary']['creation callback'] = 'entity_metadata_create_object';
- $entity_info['taxonomy_vocabulary']['save callback'] = 'taxonomy_vocabulary_save';
- $entity_info['taxonomy_vocabulary']['deletion callback'] = 'taxonomy_vocabulary_delete';
- $entity_info['taxonomy_vocabulary']['form callback'] = 'entity_metadata_form_taxonomy_vocabulary';
-
- $entity_info['taxonomy_term']['token type'] = 'term';
- $entity_info['taxonomy_vocabulary']['token type'] = 'vocabulary';
- }
- }
- function entity_ctools_plugin_directory($module, $plugin) {
- if ($module == 'ctools') {
- return "ctools/$plugin";
- }
- }
|