Loading core/modules/file/file.module +1 −1 Original line number Diff line number Diff line Loading @@ -1080,7 +1080,7 @@ function template_preprocess_file_link(&$variables) { // Set file classes to the options array. $variables['attributes'] = new Attribute($variables['attributes']); $variables['attributes']->addClass($classes); $variables['file_size'] = format_size($file->getSize() ?? 0); $variables['file_size'] = $file->getSize() !== NULL ? format_size($file->getSize()) : ''; $variables['link'] = Link::fromTextAndUrl($link_text, $url->mergeOptions($options))->toRenderable(); } Loading core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { ], ], ], ['data' => format_size($file->getSize())], ['data' => $file->getSize() !== NULL ? format_size($file->getSize()) : $this->t('Unknown')], ]; } Loading core/modules/file/tests/src/Functional/FileFieldDisplayTest.php +10 −0 Original line number Diff line number Diff line Loading @@ -232,6 +232,16 @@ public function testDescriptionDefaultFileFieldDisplay() { $this->drupalGet('node/' . $nid); $this->assertSession()->elementTextContains('xpath', '//a[@href="' . $node->{$field_name}->entity->createFileUrl() . '"]', $description); // Test that null file size is rendered as "Unknown". $nonexistent_file = File::create([ 'uri' => 'temporary://' . $this->randomMachineName() . '.txt', ]); $nonexistent_file->save(); $node->set($field_name, $nonexistent_file->id()); $node->save(); $this->drupalGet('node/' . $nid); $this->assertSession()->elementTextEquals('xpath', '//a[@href="' . $node->{$field_name}->entity->createFileUrl() . '"]/../../../td[2]', 'Unknown'); } } Loading
core/modules/file/file.module +1 −1 Original line number Diff line number Diff line Loading @@ -1080,7 +1080,7 @@ function template_preprocess_file_link(&$variables) { // Set file classes to the options array. $variables['attributes'] = new Attribute($variables['attributes']); $variables['attributes']->addClass($classes); $variables['file_size'] = format_size($file->getSize() ?? 0); $variables['file_size'] = $file->getSize() !== NULL ? format_size($file->getSize()) : ''; $variables['link'] = Link::fromTextAndUrl($link_text, $url->mergeOptions($options))->toRenderable(); } Loading
core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { ], ], ], ['data' => format_size($file->getSize())], ['data' => $file->getSize() !== NULL ? format_size($file->getSize()) : $this->t('Unknown')], ]; } Loading
core/modules/file/tests/src/Functional/FileFieldDisplayTest.php +10 −0 Original line number Diff line number Diff line Loading @@ -232,6 +232,16 @@ public function testDescriptionDefaultFileFieldDisplay() { $this->drupalGet('node/' . $nid); $this->assertSession()->elementTextContains('xpath', '//a[@href="' . $node->{$field_name}->entity->createFileUrl() . '"]', $description); // Test that null file size is rendered as "Unknown". $nonexistent_file = File::create([ 'uri' => 'temporary://' . $this->randomMachineName() . '.txt', ]); $nonexistent_file->save(); $node->set($field_name, $nonexistent_file->id()); $node->save(); $this->drupalGet('node/' . $nid); $this->assertSession()->elementTextEquals('xpath', '//a[@href="' . $node->{$field_name}->entity->createFileUrl() . '"]/../../../td[2]', 'Unknown'); } }