summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-09-26 14:50:14 (GMT)
committerAlex Pott2015-09-26 14:50:14 (GMT)
commitd59b87995e03b526a6c5a4ffae71d56b7a94316a (patch)
tree562cffcd51c2869ef40874eaf2cc47cf1c603468
parentf8e139ce68c4fae881931b1d11587e11a0ed841a (diff)
Issue #2569897 by swentel, Les Lim, mbaynton, yched, xjm: Required Long Text With Summary + form rebuild = PHP fatal error
-rw-r--r--core/modules/field/src/Tests/String/StringFieldTest.php2
-rw-r--r--core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php10
-rw-r--r--core/modules/text/src/Tests/TextFieldTest.php59
3 files changed, 69 insertions, 2 deletions
diff --git a/core/modules/field/src/Tests/String/StringFieldTest.php b/core/modules/field/src/Tests/String/StringFieldTest.php
index f59d507..3114490 100644
--- a/core/modules/field/src/Tests/String/StringFieldTest.php
+++ b/core/modules/field/src/Tests/String/StringFieldTest.php
@@ -22,7 +22,7 @@ class StringFieldTest extends WebTestBase {
*
* @var array
*/
- public static $modules = array('entity_test');
+ public static $modules = array('entity_test', 'file');
/**
* A user without any special permissions.
diff --git a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php
index 8349f7a..d3c9cd3 100644
--- a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php
+++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php
@@ -92,7 +92,15 @@ class TextareaWithSummaryWidget extends TextareaWidget {
*/
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
$element = parent::errorElement($element, $violation, $form, $form_state);
- return ($element === FALSE) ? FALSE : $element[$violation->arrayPropertyPath[0]];
+ if ($element === FALSE) {
+ return FALSE;
+ }
+ elseif (isset($violation->arrayPropertyPath[0])) {
+ return $element[$violation->arrayPropertyPath[0]];
+ }
+ else {
+ return $element;
+ }
}
}
diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php
index a22bc5b..a1c9ec3 100644
--- a/core/modules/text/src/Tests/TextFieldTest.php
+++ b/core/modules/text/src/Tests/TextFieldTest.php
@@ -68,6 +68,65 @@ class TextFieldTest extends StringFieldTest {
}
/**
+ * Test required long text with file upload.
+ */
+ function testRequiredLongTextWithFileUpload() {
+ // Create a text field.
+ $text_field_name = 'text_long';
+ $field_storage = entity_create('field_storage_config', array(
+ 'field_name' => $text_field_name,
+ 'entity_type' => 'entity_test',
+ 'type' => 'text_with_summary',
+ ));
+ $field_storage->save();
+ entity_create('field_config', array(
+ 'field_storage' => $field_storage,
+ 'bundle' => 'entity_test',
+ 'label' => $this->randomMachineName() . '_label',
+ 'required' => TRUE,
+ ))->save();
+
+ // Create a file field.
+ $file_field_name = 'file_field';
+ $field_storage = entity_create('field_storage_config', array(
+ 'field_name' => $file_field_name,
+ 'entity_type' => 'entity_test',
+ 'type' => 'file'
+ ));
+ $field_storage->save();
+ entity_create('field_config', array(
+ 'field_storage' => $field_storage,
+ 'bundle' => 'entity_test',
+ 'label' => $this->randomMachineName() . '_label',
+ ))->save();
+
+ entity_get_form_display('entity_test', 'entity_test', 'default')
+ ->setComponent($text_field_name, array(
+ 'type' => 'text_textarea_with_summary',
+ ))
+ ->setComponent($file_field_name, array(
+ 'type' => 'file_generic',
+ ))
+ ->save();
+ entity_get_display('entity_test', 'entity_test', 'full')
+ ->setComponent($text_field_name)
+ ->setComponent($file_field_name)
+ ->save();
+
+ $test_file = current($this->drupalGetTestFiles('text'));
+ $edit['files[file_field_0]'] = drupal_realpath($test_file->uri);
+ $this->drupalPostForm('entity_test/add', $edit, 'Upload');
+ $this->assertResponse(200);
+ $edit = array(
+ 'text_long[0][value]' => 'Long text'
+ );
+ $this->drupalPostForm(NULL, $edit, 'Save');
+ $this->assertResponse(200);
+ $this->drupalGet('entity_test/1');
+ $this->assertText('Long text');
+ }
+
+ /**
* Test widgets.
*/
function testTextfieldWidgets() {