Add an Include image in display checkbox to the image field
5 unresolved threads
Closes #2040033
Merge request reports
Activity
added 772 commits
-
9b28c7c7...ef97485d - 771 commits from branch
project:11.x
- 55df3a08 - Merge branch drupal:11.x into 2040033-add-an-include
-
9b28c7c7...ef97485d - 771 commits from branch
added 227 commits
-
baa6418a...2cfb0738 - 226 commits from branch
project:11.x
- 5a710d30 - Merge branch drupal:11.x into 2040033-add-an-include
-
baa6418a...2cfb0738 - 226 commits from branch
631 $node = $this->drupalCreateNode(['type' => $type_name]); 632 // Check image last as the assertions below assume that this is the case. 633 $image_formatters = ['hidden', 'image']; 634 foreach ($image_formatters as $formatter) { 635 if ($formatter === 'hidden') { 636 $edit = [ 637 "fields[$field_name][region]" => 'hidden', 638 ]; 639 } 640 else { 641 $edit = [ 642 "fields[$field_name][type]" => $formatter, 643 "fields[$field_name][region]" => 'content', 644 ]; 645 } 646 $this->drupalGet("admin/structure/types/manage/{$type_name}/display"); - Comment on lines +635 to +646
646 $this->drupalGet("admin/structure/types/manage/{$type_name}/display"); 647 $this->submitForm($edit, 'Save'); 648 $this->drupalGet('node/' . $node->id()); 649 // Verify that the field label is hidden when no image is attached. 650 $this->assertSession()->pageTextNotContains($field_name); 651 } 652 653 $test_image = current($this->drupalGetTestFiles('image')); 654 655 // Create a new node with the uploaded image. 656 $nid = $this->uploadNodeImage($test_image, $field_name, $type_name, 'image'); 657 658 // Check that the default formatter is displaying with the image name. 659 $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); 660 $node_storage->resetCache([$nid]); 661 $node = $node_storage->load($nid); - Comment on lines +659 to +661
We can do this in one pass with ::loadUnchanged
659 $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); 660 $node_storage->resetCache([$nid]); 661 $node = $node_storage->load($nid); 659 $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); 660 $node = $node_storage->loadUnchanged($nid);
672 $this->assertSession()->responseContains($default_output); 673 674 // Turn the "display" option off and check that the image is no longer displayed. 675 $edit = [$field_name . '[0][display]' => FALSE]; 676 $this->drupalGet('node/' . $nid . '/edit'); 677 $this->submitForm($edit, 'Save'); 678 679 $this->assertSession()->responseNotContains($default_output); 680 681 // Uncheck the display checkboxes and go to the preview. 682 $this->drupalGet("node/{$nid}/edit"); 683 $edit[$field_name . '[0][display]'] = FALSE; 684 $this->submitForm($edit, 'Preview'); 685 $this->clickLink('Back to content editing'); 686 $this->assertSession()->responseContains($field_name . '[0][display]'); 687 664 '#theme' => 'image', 665 '#uri' => $file->getFileUri(), 666 '#width' => 40, 667 '#height' => 20, 668 '#alt' => 'image', 669 '#attributes' => ['loading' => 'lazy'], 670 ]; 671 $default_output = str_replace("\n", '', (string) \Drupal::service('renderer')->renderRoot($image)); 672 $this->assertSession()->responseContains($default_output); 673 674 // Turn the "display" option off and check that the image is no longer displayed. 675 $edit = [$field_name . '[0][display]' => FALSE]; 676 $this->drupalGet('node/' . $nid . '/edit'); 677 $this->submitForm($edit, 'Save'); 678 679 $this->assertSession()->responseNotContains($default_output); 657 658 // Check that the default formatter is displaying with the image name. 659 $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); 660 $node_storage->resetCache([$nid]); 661 $node = $node_storage->load($nid); 662 $file = $node->{$field_name}->entity; 663 $image = [ 664 '#theme' => 'image', 665 '#uri' => $file->getFileUri(), 666 '#width' => 40, 667 '#height' => 20, 668 '#alt' => 'image', 669 '#attributes' => ['loading' => 'lazy'], 670 ]; 671 $default_output = str_replace("\n", '', (string) \Drupal::service('renderer')->renderRoot($image)); 672 $this->assertSession()->responseContains($default_output);
Please register or sign in to reply