diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php index 3dc6cc68e4..d23f67530d 100644 --- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php @@ -257,7 +257,8 @@ public static function validateRequiredFields($element, FormStateInterface $form // Only do validation if the function is triggered from other places than // the image process form. $triggering_element = $form_state->getTriggeringElement(); - if (empty($triggering_element['#submit']) || !in_array('file_managed_file_submit', $triggering_element['#submit'])) { + if (empty($triggering_element['#submit']) || + !in_array('file_managed_file_submit', $triggering_element['#submit'])) { // If the image is not there, we do not check for empty values. $parents = $element['#parents']; $field = array_pop($parents); diff --git a/core/modules/image/src/Tests/ImageFieldValidateTest.php b/core/modules/image/src/Tests/ImageFieldValidateTest.php index fe2281af41..924de2134e 100644 --- a/core/modules/image/src/Tests/ImageFieldValidateTest.php +++ b/core/modules/image/src/Tests/ImageFieldValidateTest.php @@ -11,6 +11,7 @@ * @group image */ class ImageFieldValidateTest extends ImageFieldTestBase { + /** * Test min/max resolution settings. */ @@ -22,27 +23,27 @@ public function testResolution() { ]; $min_resolution = [ 'width' => 50, - 'height' => 50 + 'height' => 50, ]; $max_resolution = [ 'width' => 100, - 'height' => 100 + 'height' => 100, ]; $no_height_min_resolution = [ 'width' => 50, - 'height' => NULL + 'height' => NULL, ]; $no_height_max_resolution = [ 'width' => 100, - 'height' => NULL + 'height' => NULL, ]; $no_width_min_resolution = [ 'width' => NULL, - 'height' => 50 + 'height' => 50, ]; $no_width_max_resolution = [ 'width' => NULL, - 'height' => 100 + 'height' => 100, ]; $field_settings = [ 0 => $this->getFieldSettings($min_resolution, $max_resolution), @@ -150,8 +151,9 @@ public function testRequiredAttributes() { * The maximum width and height resolution setting. * * @return array + * An array with the field settings. */ - protected function getFieldSettings($min_resolution, $max_resolution) { + protected function getFieldSettings(array $min_resolution, array $max_resolution) { return [ 'max_resolution' => $max_resolution['width'] . 'x' . $max_resolution['height'], 'min_resolution' => $min_resolution['width'] . 'x' . $min_resolution['height'], @@ -163,8 +165,8 @@ protected function getFieldSettings($min_resolution, $max_resolution) { * Tests that image field validation works with other form submit handlers. */ public function testFriendlyAjaxValidation() { - // Add a custom field to the Article content type that contains - // an AJAX handler on a select field. + // Add a custom field to the Article content type that contains an AJAX + // handler on a select field. $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_dummy_select', 'type' => 'image_module_test_dummy_ajax', @@ -181,11 +183,20 @@ public function testFriendlyAjaxValidation() { 'label' => t('Dummy select'), ])->save(); - entity_get_form_display('node', 'article', 'default') - ->setComponent('field_dummy_select', array( + $entity_form_display = \Drupal::entityTypeManager() + ->getStorage('entity_form_display') + ->create([ + 'targetEntityType' => 'node', + 'bundle' => 'article', + 'mode' => 'default', + 'status' => TRUE, + ]); + $entity_form_display->setComponent( + 'field_dummy_select', + [ 'type' => 'image_module_test_dummy_ajax_widget', 'weight' => 1, - )) + ]) ->save(); // Then, add an image field. @@ -193,9 +204,10 @@ public function testFriendlyAjaxValidation() { // Open an article and trigger the AJAX handler. $this->drupalGet('node/add/article'); - $edit = array( + $edit = [ 'field_dummy_select[select_widget]' => 'bam', - ); + ]; $this->drupalPostAjaxForm(NULL, $edit, 'field_dummy_select[select_widget]'); } + } diff --git a/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldWidget/DummyAjaxWidget.php b/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldWidget/DummyAjaxWidget.php index d3ebc3442d..d7e5b3f406 100644 --- a/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldWidget/DummyAjaxWidget.php +++ b/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldWidget/DummyAjaxWidget.php @@ -8,7 +8,7 @@ use Drupal\Core\Form\FormStateInterface; /** - * Default widget for Zeus videos. + * Dummy AJAX widget. * * @FieldWidget( * id = "image_module_test_dummy_ajax_widget", @@ -40,7 +40,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen } /** - * Ajax callback to update the video widget fields when select is changed. + * Ajax callback to update the Dummy AJAX widget when it is changed. * * @param array $form * The build form. @@ -48,7 +48,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen * The form state. * * @return \Drupal\Core\Ajax\AjaxResponse - * Ajax response with updated widget for video. + * Ajax response with updated widget. */ public static function dummyAjaxCallback(array &$form, FormStateInterface $form_state) { return new AjaxResponse();