Skip to content
Snippets Groups Projects
Commit 394862da authored by catch's avatar catch
Browse files

Issue #1848040 by yched: Fixed Fatal error on 'Manage display' after creating new field.

parent 5b6721a2
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -101,7 +101,18 @@ public function form(array $form, array &$form_state) { ...@@ -101,7 +101,18 @@ public function form(array $form, array &$form_state) {
// Field rows. // Field rows.
foreach ($instances as $name => $instance) { foreach ($instances as $name => $instance) {
$field = field_info_field($instance['field_name']); $field = field_info_field($instance['field_name']);
$display = $instance['display'][$this->view_mode];
if (isset($instance['display'][$this->view_mode])) {
$display = $instance['display'][$this->view_mode];
}
else {
$display = array(
'type' => 'hidden',
'label' => 'above',
'weight' => 0,
);
}
$table[$name] = array( $table[$name] = array(
'#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
'#row_type' => 'field', '#row_type' => 'field',
......
...@@ -167,6 +167,27 @@ function testViewModeCustom() { ...@@ -167,6 +167,27 @@ function testViewModeCustom() {
$this->assertNodeViewNoText($node, 'rss', $value, "The previous settings are kept when 'rss' mode is specialized again."); $this->assertNodeViewNoText($node, 'rss', $value, "The previous settings are kept when 'rss' mode is specialized again.");
} }
/**
* Tests that field instances with no explicit display settings do not break.
*/
function testNonInitializedFields() {
// Create a test field.
$edit = array(
'fields[_add_new_field][label]' => 'Test',
'fields[_add_new_field][field_name]' => 'test',
);
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $edit);
// Check that no settings have been set for the 'teaser' mode.
$instance = field_info_instance('node', 'field_test', $this->type);
$this->assertFalse(isset($instance['display']['teaser']));
// Check that the field appears as 'hidden' on the 'Manage display' page
// for the 'teaser' mode.
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/display/teaser');
$this->assertFieldByName('fields[field_test][type]', 'hidden', 'The field is displayed as \'hidden \'.');
}
/** /**
* Tests hiding the view modes fieldset when there's only one available. * Tests hiding the view modes fieldset when there's only one available.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment