previewNodeImage example

// Test for absence of link to image styles configuration.     $this->submitForm([], "{$field_name}_settings_edit");
    $this->assertSession()->linkByHrefNotExists(Url::fromRoute('entity.image_style.collection')->toString(), 'Link to image styles configuration is absent when permissions are insufficient');

    // Restore 'administer image styles' permission to testing admin user     user_role_change_permissions(reset($admin_user_roles)['administer image styles' => TRUE]);

    // Create a new node with an image attached.     $test_image = current($this->drupalGetTestFiles('image'));

    // Ensure that preview works.     $this->previewNodeImage($test_image$field_name, 'article');

    // After previewing, make the alt field required. It cannot be required     // during preview because the form validation will fail.     $instance->setSetting('alt_field_required', 1);
    $instance->save();

    // Create alt text for the image.     $alt = $this->randomMachineName();

    // Save node.     $nid = $this->uploadNodeImage($test_image$field_name, 'article', $alt);
    
    $display_options = [
      'type' => 'responsive_image',
      'settings' => [
        'image_link' => $link_type,
        'responsive_image_style' => 'style_one',
      ],
    ];
    $display_repository->getViewDisplay('node', 'article')
      ->setComponent($field_name$display_options)
      ->save();
    // Ensure that preview works.     $this->previewNodeImage($test_image$field_name, 'article');

    // Look for a picture tag in the preview output     $this->assertSession()->responseMatches('/picture/');

    $nid = $this->uploadNodeImage($test_image$field_name, 'article');
    $this->container->get('entity_type.manager')->getStorage('node')->resetCache([$nid]);
    $node = Node::load($nid);

    // Use the responsive image formatter linked to file formatter.     $display_options = [
      'type' => 'responsive_image',
      
Home | Imprint | This part of the site doesn't use cookies.