Skip to content
This repository was archived by the owner on Jan 5, 2018. It is now read-only.

Commit 9f7799d

Browse files
gitslashrsm
authored andcommitted
Issue #2712863 by Denchev, slashrsm: Fix PluginNotFoundException for entity:file:undefined if installing when there are already images/files.
1 parent 3cfd9e2 commit 9f7799d

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/Form/FileEditForm.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22

3-
/**
4-
* @file
5-
* Definition of Drupal\file_entity\Form\FileEditForm.
6-
*/
7-
83
namespace Drupal\file_entity\Form;
94

105
use Drupal\Core\Entity\ContentEntityForm;
@@ -23,6 +18,15 @@ class FileEditForm extends ContentEntityForm {
2318

2419
use UploadValidatorsTrait;
2520

21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function prepareEntity() {
25+
if ($this->entity->bundle() == FILE_TYPE_NONE) {
26+
$this->entity->updateBundle();
27+
}
28+
}
29+
2630
/**
2731
* {@inheritdoc}
2832
*/

src/Form/FileInlineEditForm.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<?php
2-
/**
3-
* @file
4-
* Contains \Drupal\file_entity\Form\FileInlineEditForm.
5-
*/
62

73
namespace Drupal\file_entity\Form;
84

@@ -43,5 +39,4 @@ protected function actionsElement(array $form, FormStateInterface $form_state) {
4339
return $elements;
4440
}
4541

46-
4742
}

src/Tests/FileEntityFileTypeClassificationTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22

3-
/**
4-
* @file
5-
* Contains \Drupal\file_entity\Tests\FileEntityFileTypeClassificationTest.
6-
*/
7-
83
namespace Drupal\file_entity\Tests;
94

105
use Drupal\file\Entity\File;
@@ -73,6 +68,16 @@ function testFileTypeClassification() {
7368
$file_type = $this->getFileType($image_file);
7469
$this->assertEqual($file_type['type'], 'undefined', t('The image file has an undefined file type.'));
7570

71+
// When editing files before cron has run the bundle should have been
72+
// updated.
73+
$account = $this->drupalCreateUser(['bypass file access']);
74+
$this->drupalLogin($account);
75+
$this->assertNotEqual($image_file->bundle(), 'image', 'The image file does not have correct bundle before loading it.');
76+
$this->drupalGet('file/' . $image_file->id() . '/edit');
77+
$this->drupalPostForm(NULL, [], t('Save'));
78+
$image_file = File::load($image_file->id());
79+
$this->assertEqual($image_file->bundle(), 'image', 'The image file has correct bundle after load.');
80+
7681
// The classification queue is processed during cron runs. Run cron to
7782
// trigger the classification process.
7883
$this->cronRun();
@@ -85,4 +90,5 @@ function testFileTypeClassification() {
8590
$file_type = $this->getFileType($image_file);
8691
$this->assertEqual($file_type['type'], 'image', t('The image file was properly assigned the Image file type.'));
8792
}
93+
8894
}

0 commit comments

Comments
 (0)