Skip to content
Snippets Groups Projects
Commit 660165cc authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2226171 by LinL, valthebald: Preview in Create Article gives error.

parent 5efa7d55
No related branches found
No related tags found
No related merge requests found
......@@ -102,9 +102,11 @@ public function viewElements(FieldItemListInterface $items) {
// Check if the formatter involves a link.
if ($image_link_setting == 'content') {
$entity = $items->getEntity();
// @todo Remove when theme_image_formatter() has support for route name.
$uri['path'] = $entity->getSystemPath();
$uri['options'] = $entity->urlInfo()->getOptions();
if (!$entity->isNew()) {
// @todo Remove when theme_image_formatter() has support for route name.
$uri['path'] = $entity->getSystemPath();
$uri['options'] = $entity->urlInfo()->getOptions();
}
}
elseif ($image_link_setting == 'file') {
$link_file = TRUE;
......
......@@ -54,6 +54,11 @@ function _testImageFieldFormatters($scheme) {
// 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');
// Save node.
$nid = $this->uploadNodeImage($test_image, $field_name, 'article');
$node = node_load($nid, TRUE);
......
......@@ -98,6 +98,24 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc
}
/**
* Preview an image in a node.
*
* @param \Drupal\Core\Image\ImageInterface $image
* A file object representing the image to upload.
* @param string $field_name
* Name of the image field the image should be attached to.
* @param string $type
* The type of node to create.
*/
function previewNodeImage($image, $field_name, $type) {
$edit = array(
'title[0][value]' => $this->randomName(),
);
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
$this->drupalPostForm('node/add/' . $type, $edit, t('Preview'));
}
/**
* Upload an image to a node.
*
......
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