summaryrefslogtreecommitdiff
path: root/modules/field_ui
diff options
context:
space:
mode:
Diffstat (limited to 'modules/field_ui')
-rw-r--r--modules/field_ui/field_ui.admin.inc9
-rw-r--r--modules/field_ui/field_ui.test5
2 files changed, 12 insertions, 2 deletions
diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc
index eb94ed6c7..4104e04cf 100644
--- a/modules/field_ui/field_ui.admin.inc
+++ b/modules/field_ui/field_ui.admin.inc
@@ -787,8 +787,13 @@ function field_ui_existing_field_options($obj_type, $bundle) {
if (!($existing_bundle == $bundle && $existing_obj_type == $obj_type)) {
foreach ($instances as $instance) {
$field = field_info_field($instance['field_name']);
- // Don't show locked fields or fields already in the current bundle.
- if (empty($field['locked']) && !field_info_instance($obj_type, $field['field_name'], $bundle)) {
+ // Don't show
+ // - locked fields,
+ // - fields already in the current bundle,
+ // - field that cannot be added to the object type.
+ if (empty($field['locked'])
+ && !field_info_instance($obj_type, $field['field_name'], $bundle)
+ && (empty($field['object_types']) || in_array($obj_type, $field['object_types']))) {
$text = t('@type: @field (@label)', array(
'@type' => $field_types[$field['type']]['label'],
'@label' => t($instance['label']), '@field' => $instance['field_name'],
diff --git a/modules/field_ui/field_ui.test b/modules/field_ui/field_ui.test
index f14ed11c0..e3f030782 100644
--- a/modules/field_ui/field_ui.test
+++ b/modules/field_ui/field_ui.test
@@ -146,6 +146,11 @@ class FieldUITestCase extends DrupalWebTestCase {
$this->drupalGet(('admin/structure/types/manage/page/fields'));
$this->assertRaw(t('Add existing field'), t('"Add existing field" was found.'));
+ // Check that the list of options respects object type restrictions on
+ // fields. The 'comment' field is restricted to the 'comment' object type
+ // and should not appear in the list.
+ $this->assertFalse($this->xpath('//select[@id="edit--add-existing-field-field-name"]//option[@value="comment"]'), t('The list of options respects object type restrictions.'));
+
// Add a new field based on an existing field.
$edit = array(
'_add_existing_field[label]' => $this->field_label . '_2',