summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-03-28 11:08:30 +0000
committerDries Buytaert <dries@buytaert.net>2010-03-28 11:08:30 +0000
commitfdb422b8a27539938404cdc3d1a1b73bc01f5d4a (patch)
tree74713be38cd84990f289427e828b26e7e0a8ec8d
parentcf7750838d0e4d47928478776245f041030c1ac4 (diff)
downloadbrdo-fdb422b8a27539938404cdc3d1a1b73bc01f5d4a.tar.gz
brdo-fdb422b8a27539938404cdc3d1a1b73bc01f5d4a.tar.bz2
- Patch #742318 by sun, yched: fields are editable regardless of whether an bundle instance exists, missing menu titles, etc.
-rw-r--r--modules/comment/comment.module30
-rw-r--r--modules/field_ui/field_ui.admin.inc40
-rw-r--r--modules/field_ui/field_ui.module88
3 files changed, 111 insertions, 47 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index aa66c9f87..8ab3925d7 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -287,6 +287,21 @@ function comment_menu() {
}
/**
+ * Implements hook_menu_alter().
+ */
+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;
+}
+
+/**
* Returns a menu title which includes the number of unapproved comments.
*/
function comment_count_unpublished() {
@@ -2505,21 +2520,6 @@ function comment_ranking() {
}
/**
- * Implements hook_menu_alter().
- */
-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;
-}
-
-/**
* Implements hook_rdf_mapping().
*/
function comment_rdf_mapping() {
diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc
index ba8927192..a775a71f9 100644
--- a/modules/field_ui/field_ui.admin.inc
+++ b/modules/field_ui/field_ui.admin.inc
@@ -812,15 +812,10 @@ function field_ui_existing_field_options($entity_type, $bundle) {
/**
* Menu callback; presents the field settings edit page.
*/
-function field_ui_field_settings_form($form, &$form_state, $entity_type, $bundle, $field) {
- $bundle = field_extract_bundle($entity_type, $bundle);
- $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
-
- // When a field is first created, we have to get data from the db.
- if (!isset($instance['label'])) {
- $instance = field_read_instance($field['field_name'], $bundle);
- $field = field_read_field($field['field_name']);
- }
+function field_ui_field_settings_form($form, &$form_state, $instance) {
+ $bundle = $instance['bundle'];
+ $entity_type = $instance['entity_type'];
+ $field = field_info_field($instance['field_name']);
drupal_set_title($instance['label']);
@@ -900,9 +895,10 @@ 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, $entity_type, $bundle, $field) {
- $bundle = field_extract_bundle($entity_type, $bundle);
- $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
+function field_ui_widget_type_form($form, &$form_state, $instance) {
+ $bundle = $instance['bundle'];
+ $entity_type = $instance['entity_type'];
+ $field = field_info_field($instance['field_name']);
drupal_set_title($instance['label']);
@@ -962,9 +958,11 @@ 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, $entity_type, $bundle, $field) {
- $bundle = field_extract_bundle($entity_type, $bundle);
- $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
+function field_ui_field_delete_form($form, &$form_state, $instance) {
+ $bundle = $instance['bundle'];
+ $entity_type = $instance['entity_type'];
+ $field = field_info_field($instance['field_name']);
+
$admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
$form['entity_type'] = array('#type' => 'value', '#value' => $entity_type);
@@ -1020,9 +1018,12 @@ 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, $entity_type, $bundle, $field) {
- $bundle = field_extract_bundle($entity_type, $bundle);
- $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
+function field_ui_field_edit_form($form, &$form_state, $instance) {
+ $bundle = $instance['bundle'];
+ $entity_type = $instance['entity_type'];
+ $field = field_info_field($instance['field_name']);
+
+ drupal_set_title($instance['label']);
$form['#field'] = $field;
@@ -1037,9 +1038,6 @@ function field_ui_field_edit_form($form, &$form_state, $entity_type, $bundle, $f
$widget_type = field_info_widget_types($instance['widget']['type']);
$bundles = field_info_bundles();
- $title = isset($instance['label']) ? $instance['label'] : $instance['field_name'];
- drupal_set_title(check_plain($title));
-
// Create a form structure for the instance values.
$form['instance'] = array(
'#tree' => TRUE,
diff --git a/modules/field_ui/field_ui.module b/modules/field_ui/field_ui.module
index 2642d80f3..5680c0fd2 100644
--- a/modules/field_ui/field_ui.module
+++ b/modules/field_ui/field_ui.module
@@ -71,12 +71,29 @@ function field_ui_menu() {
if ($info['fieldable']) {
foreach ($info['bundles'] as $bundle_name => $bundle_info) {
if (isset($bundle_info['admin'])) {
- // Extract informations from the bundle description.
+ // Extract path information from the bundle.
$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')));
+ // Different bundles can appear on the same path (e.g. %node_type and
+ // %comment_node_type). To allow field_ui_menu_load() to extract the
+ // actual bundle object from the translated menu router path
+ // arguments, we need to identify the argument position of the bundle
+ // name string ('bundle argument') and pass that position to the menu
+ // loader. The position needs to be casted into a string; otherwise it
+ // would be replaced with the bundle name string.
+ if (isset($bundle_info['admin']['bundle argument'])) {
+ $bundle_arg = $bundle_info['admin']['bundle argument'];
+ $bundle_pos = (string) $bundle_arg;
+ }
+ else {
+ $bundle_arg = $bundle_name;
+ $bundle_pos = '0';
+ }
+ // This is the position of the %field_ui_menu placeholder in the
+ // items below.
$field_position = count(explode('/', $path)) + 1;
+ $access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array('access callback', 'access arguments')));
+
$items["$path/fields"] = array(
'title' => 'Manage fields',
'page callback' => 'drupal_get_form',
@@ -86,33 +103,45 @@ function field_ui_menu() {
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu"] = array(
+ 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'title callback' => 'field_ui_menu_title',
+ 'title arguments' => array($field_position),
'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_edit_form', $entity_type, $bundle_arg, $field_position),
+ 'page arguments' => array('field_ui_field_edit_form', $field_position),
'type' => MENU_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/edit"] = array(
+ 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'title' => 'Edit',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_edit_form', $entity_type, $bundle_arg, $field_position),
+ 'page arguments' => array('field_ui_field_edit_form', $field_position),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/field-settings"] = array(
+ 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'title' => 'Field settings',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_settings_form', $entity_type, $bundle_arg, $field_position),
+ 'page arguments' => array('field_ui_field_settings_form', $field_position),
'type' => MENU_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/widget-type"] = array(
+ 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'title' => 'Widget type',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_widget_type_form', $entity_type, $bundle_arg, $field_position),
+ 'page arguments' => array('field_ui_widget_type_form', $field_position),
'type' => MENU_LOCAL_TASK,
'file' => 'field_ui.admin.inc',
) + $access;
$items["$path/fields/%field_ui_menu/delete"] = array(
+ 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'),
+ 'title' => 'Delete',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('field_ui_field_delete_form', $entity_type, $bundle_arg, $field_position),
+ 'page arguments' => array('field_ui_field_delete_form', $field_position),
'type' => MENU_LOCAL_TASK,
+ 'weight' => 10,
'file' => 'field_ui.admin.inc',
) + $access;
@@ -143,16 +172,53 @@ function field_ui_menu() {
}
/**
- * Menu loader; Load a field based on its name.
+ * Menu loader; Load a field instance based on field and bundle name.
+ *
+ * @param $field_name
+ * The name of the field, as contained in the path.
+ * @param $entity_type
+ * The name of the entity.
+ * @param $bundle_name
+ * The name of the bundle, as contained in the path.
+ * @param $bundle_pos
+ * The position of $bundle_name in $map.
+ * @param $map
+ * The translated menu router path argument map.
*/
-function field_ui_menu_load($field_name) {
+function field_ui_menu_load($field_name, $entity_type, $bundle_name, $bundle_pos, $map) {
+ // Extract the actual bundle name from the translated argument map.
+ // The menu router path to manage fields of an entity can be shared among
+ // multiple bundles. For example:
+ // - admin/structure/types/manage/%node_type/fields/%field_ui_menu
+ // - admin/structure/types/manage/%comment_node_type/fields/%field_ui_menu
+ // The menu system will automatically load the correct bundle depending on the
+ // actual path arguments, but this menu loader function only receives the node
+ // type string as $bundle_name, which is not the bundle name for comments.
+ // We therefore leverage the dynamically translated $map provided by the menu
+ // system to retrieve the actual bundle and bundle name for the current path.
+ if ($bundle_pos > 0) {
+ $bundle = $map[$bundle_pos];
+ $bundle_name = field_extract_bundle($entity_type, $bundle);
+ }
+ // Check whether the field exists at all.
if ($field = field_info_field($field_name)) {
- return $field;
+ // Only return the field if a field instance exists for the given entity
+ // type and bundle.
+ if ($instance = field_info_instance($entity_type, $field_name, $bundle_name)) {
+ return $instance;
+ }
}
return FALSE;
}
/**
+ * Menu title callback.
+ */
+function field_ui_menu_title($instance) {
+ return t($instance['label']);
+}
+
+/**
* Implements hook_theme().
*/
function field_ui_theme() {