diff --git a/entity.module b/entity.module index c4df05f..7d7d34d 100644 --- a/entity.module +++ b/entity.module @@ -979,3 +979,12 @@ function entity_entity_info_alter(&$entity_info) { } } +/** + * Implements hook_ctools_plugin_directory(). + */ +function entity_ctools_plugin_directory($module, $plugin) { + if ($module == 'ctools' && !empty($plugin)) { + return "plugins/$plugin"; + } +} + diff --git a/plugins/content_types/entity/entity.inc b/plugins/content_types/entity/entity.inc new file mode 100644 index 0000000..ae685ad --- /dev/null +++ b/plugins/content_types/entity/entity.inc @@ -0,0 +1,105 @@ + t('Entity provided by Entity API'), + 'content type' => 'entity_entity_content_type_content_type', +); + +/** + * Just one subtype. + * + * Ordinarily this function is meant to get just one subtype. However, we are + * using it to deal with the fact that we have changed the subtype names. This + * lets us translate the name properly. + */ +function entity_entity_content_type_content_type($subtype) { + $types = entity_entity_content_type_content_types(); + if (isset($types[$subtype])) { + return $types[$subtype]; + } +} + +/** + * Return all field content types available. + */ +function entity_entity_content_type_content_types() { + // This will hold all the properties. + $types = array(); + $context_types = array(); + $info = entity_get_property_info(); + + // TODO: make more generic. + // Site isn't a real entity, so remove it. + unset($info['site']); + + foreach ($info as $entity_type => $data) { + foreach ($data['properties'] as $name => $property) { + $property += array('description' => ''); + $types[$entity_type . ':' . $name] = array( + 'category' => t(ucfirst($entity_type)), + 'icon' => 'icon_entity.png', + 'title' => $property['label'], + 'description' => $property['description'], + 'required context' => new ctools_context_required(t(ucfirst($entity_type)), $entity_type), + ); + } + } + + return $types; +} + +/** +* Render the custom content type. +*/ +function entity_entity_content_type_render($subtype, $conf, $panel_args, $context) { + if (empty($context) || empty($context->data)) { + return; + } + + // Get a shortcut to the entity. + $entity = $context->data; + list($entity_type, $name) = explode(':', $subtype, 2); + + $wrapper = entity_metadata_wrapper($entity_type, $entity); + if (!$wrapper) { + return; + } + + // Access check on the property. + if (!$wrapper->{$name}->access('view')) { + return; + } + + $info = entity_get_property_info($entity_type); + $title = $info['properties'][$name]['label']; + + // Build the content type block. + $block = new stdClass(); + $block->module = 'entity'; + $block->title = $title; + $block->content = $wrapper->{$name}->value(); + $block->delta = str_replace('_', '-', $entity_type . '-' . $name); + + return $block; +} + +/** +* Returns an edit form for custom type settings. +*/ +function entity_entity_content_type_edit_form($form, &$form_state) { + // This is here so we have default form options. + return $form; +} + + +/** +* Returns the administrative title for a type. +*/ +function entity_entity_content_type_admin_title($subtype, $conf, $context) { + return t('"@s" @name', array('@s' => $context->identifier, '@name' => $subtype)); +}