Commit ec785891 authored by webchick's avatar webchick

#537750 by yched: Added Field UI for comments.

parent 5aebca5a
......@@ -104,9 +104,6 @@ function comment_entity_info() {
'id' => 'cid',
'bundle' => 'node_type',
),
'bundle keys' => array(
'bundle' => 'type',
),
'bundles' => array(),
'view modes' => array(
'full' => array(
......@@ -120,12 +117,36 @@ function comment_entity_info() {
foreach (node_type_get_names() as $type => $name) {
$return['comment']['bundles']['comment_node_' . $type] = array(
'label' => $name,
'admin' => array(
// Place the Field UI paths for comments one level below the
// corresponding paths for nodes, so that they appear in the same set
// of local tasks. Note that the paths use a different placeholder name
// and thus a different menu loader callback, so that Field UI page
// callbacks get a comment bundle name from the node type in the URL.
// @see comment_node_type_load()
// @see comment_menu_alter()
'path' => 'admin/structure/types/manage/%comment_node_type/comment',
'bundle argument' => 4,
'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type) . '/comment',
'access arguments' => array('administer content types'),
),
);
}
return $return;
}
/**
* Menu loader callback for Field UI paths.
*
* Return a comment bundle name from a node type in the URL.
*/
function comment_node_type_load($name) {
if ($type = node_type_get_type(strtr($name, array('-' => '_')))) {
return 'comment_node_' . $type->type;
}
}
/**
* Entity path callback.
*/
......@@ -133,6 +154,32 @@ function comment_path($comment) {
return 'comment/' . $comment->cid;
}
/**
* Implements hook_field_extra_fields().
*/
function comment_field_extra_fields() {
$return = array();
foreach (node_type_get_types() as $type) {
if (variable_get('comment_subject_field_' . $type->type, 1) == 1) {
$return['comment']['comment_node_' . $type->type] = array(
'author' => array(
'label' => t('Author'),
'description' => t('Author textfield'),
'weight' => -2,
),
'title' => array(
'label' => t('Subject'),
'description' => t('Subject textfield'),
'weight' => -1,
),
);
}
}
return $return;
}
/**
* Implements hook_theme().
*/
......@@ -2501,6 +2548,13 @@ function comment_ranking() {
function comment_menu_alter(&$items) {
// Add comments to the description for admin/content.
$items['admin/content']['description'] = "Administer content and comments";
// Adjust the Field UI tabs on admin/structure/types/manage/[node-type].
// @see comment_entity_info()
$items['admin/structure/types/manage/%comment_node_type/comment/fields']['title'] = 'Comment fields';
$items['admin/structure/types/manage/%comment_node_type/comment/fields']['weight'] = 3;
$items['admin/structure/types/manage/%comment_node_type/comment/display']['title'] = 'Comment display';
$items['admin/structure/types/manage/%comment_node_type/comment/display']['weight'] = 4;
}
/**
......
......@@ -812,9 +812,9 @@ function field_ui_existing_field_options($obj_type, $bundle) {
/**
* Menu callback; presents the field settings edit page.
*/
function field_ui_field_settings_form($form, &$form_state, $obj_type, $bundle, $instance) {
function field_ui_field_settings_form($form, &$form_state, $obj_type, $bundle, $field) {
$bundle = field_extract_bundle($obj_type, $bundle);
$field = field_info_field($instance['field_name']);
$instance = field_info_instance($obj_type, $field['field_name'], $bundle);
// When a field is first created, we have to get data from the db.
if (!isset($instance['label'])) {
......@@ -900,9 +900,11 @@ function field_ui_field_settings_form_submit($form, &$form_state) {
/**
* Menu callback; select a widget for the field.
*/
function field_ui_widget_type_form($form, &$form_state, $obj_type, $bundle, $instance) {
function field_ui_widget_type_form($form, &$form_state, $obj_type, $bundle, $field) {
$bundle = field_extract_bundle($obj_type, $bundle);
$field = field_read_field($instance['field_name']);
$instance = field_info_instance($obj_type, $field['field_name'], $bundle);
drupal_set_title($instance['label']);
$field_type = field_info_field_types($field['type']);
$widget_type = field_info_widget_types($instance['widget']['type']);
......@@ -960,9 +962,9 @@ function field_ui_widget_type_form_submit($form, &$form_state) {
/**
* Menu callback; present a form for removing a field from a content type.
*/
function field_ui_field_delete_form($form, &$form_state, $obj_type, $bundle, $instance) {
function field_ui_field_delete_form($form, &$form_state, $obj_type, $bundle, $field) {
$bundle = field_extract_bundle($obj_type, $bundle);
$field = field_info_field($instance['field_name']);
$instance = field_info_instance($obj_type, $field['field_name'], $bundle);
$admin_path = _field_ui_bundle_admin_path($obj_type, $bundle);
$form['object_type'] = array('#type' => 'value', '#value' => $obj_type);
......@@ -1017,10 +1019,10 @@ function field_ui_field_delete_form_submit($form, &$form_state) {
/**
* Menu callback; presents the field instance edit page.
*/
function field_ui_field_edit_form($form, &$form_state, $obj_type, $bundle, $instance) {
function field_ui_field_edit_form($form, &$form_state, $obj_type, $bundle, $field) {
$bundle = field_extract_bundle($obj_type, $bundle);
$instance = field_info_instance($obj_type, $field['field_name'], $bundle);
$field = field_info_field($instance['field_name']);
$form['#field'] = $field;
if (!empty($field['locked'])) {
......
......@@ -56,7 +56,7 @@ function field_ui_menu() {
$path = $bundle_info['admin']['path'];
$bundle_arg = isset($bundle_info['admin']['bundle argument']) ? $bundle_info['admin']['bundle argument'] : $bundle_name;
$access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array('access callback', 'access arguments')));
$instance_position = count(explode('/', $path)) + 1;
$field_position = count(explode('/', $path)) + 1;
$items["$path/fields"] = array(
'title' => 'Manage fields',
......@@ -67,43 +67,32 @@ function field_ui_menu() {
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu"] = array(
'title callback' => 'field_ui_menu_label',
'title arguments' => array($instance_position),
'load arguments' => array($obj_type, $bundle_arg),
'page callback' => 'drupal_get_form',
'page arguments' => array('field_ui_field_edit_form', $obj_type, $bundle_arg, $instance_position),
'page arguments' => array('field_ui_field_edit_form', $obj_type, $bundle_arg, $field_position),
'type' => MENU_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/edit"] = array(
'title' => 'Edit instance settings',
'load arguments' => array($obj_type, $bundle_arg),
'page callback' => 'drupal_get_form',
'page arguments' => array('field_ui_field_edit_form', $obj_type, $bundle_arg, $instance_position),
'page arguments' => array('field_ui_field_edit_form', $obj_type, $bundle_arg, $field_position),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/field-settings"] = array(
'title' => 'Edit field settings',
'load arguments' => array($obj_type, $bundle_arg),
'page callback' => 'drupal_get_form',
'page arguments' => array('field_ui_field_settings_form', $obj_type, $bundle_arg, $instance_position),
'page arguments' => array('field_ui_field_settings_form', $obj_type, $bundle_arg, $field_position),
'type' => MENU_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/widget-type"] = array(
'title' => 'Change widget type',
'load arguments' => array($obj_type, $bundle_arg),
'page callback' => 'drupal_get_form',
'page arguments' => array('field_ui_widget_type_form', $obj_type, $bundle_arg, $instance_position),
'page arguments' => array('field_ui_widget_type_form', $obj_type, $bundle_arg, $field_position),
'type' => MENU_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/delete"] = array(
'title' => 'Delete instance',
'load arguments' => array($obj_type, $bundle_arg),
'page callback' => 'drupal_get_form',
'page arguments' => array('field_ui_field_delete_form', $obj_type, $bundle_arg, $instance_position),
'page arguments' => array('field_ui_field_delete_form', $obj_type, $bundle_arg, $field_position),
'type' => MENU_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
......@@ -135,23 +124,15 @@ function field_ui_menu() {
}
/**
* Menu loader; Load a field instance based on its name.
* Menu loader; Load a field based on its name.
*/
function field_ui_menu_load($field_name, $obj_type, $bundle_name) {
$bundle_name = strtr($bundle_name, array('-' => '_'));
if ($instance = field_info_instance($obj_type, $field_name, $bundle_name)) {
return $instance;
function field_ui_menu_load($field_name) {
if ($field = field_info_field($field_name)) {
return $field;
}
return FALSE;
}
/**
* Menu title callback; Return a field label based on its instance.
*/
function field_ui_menu_label($instance) {
return t($instance['label']);
}
/**
* Implements hook_theme().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment