diff --git a/src/Form/FileEditForm.php b/src/Form/FileEditForm.php index 658e07c..b0eb94b 100644 --- a/src/Form/FileEditForm.php +++ b/src/Form/FileEditForm.php @@ -1,10 +1,5 @@ entity->bundle() == FILE_TYPE_NONE) { + $this->entity->updateBundle(); + } + } + + /** + * {@inheritdoc} + */ public function form(array $form, FormStateInterface $form_state) { /** @var FileInterface $file */ $file = $this->entity; diff --git a/src/Form/FileInlineEditForm.php b/src/Form/FileInlineEditForm.php index c1efa53..c273a60 100644 --- a/src/Form/FileInlineEditForm.php +++ b/src/Form/FileInlineEditForm.php @@ -1,8 +1,4 @@ entity->bundle() == FILE_TYPE_NONE) { + $this->entity->updateBundle(); + } + } + + /** + * {@inheritdoc} + */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); // Point form submissions to the Ajax controller. diff --git a/src/Tests/FileEntityFileTypeClassificationTest.php b/src/Tests/FileEntityFileTypeClassificationTest.php index c86ab83..a339e82 100644 --- a/src/Tests/FileEntityFileTypeClassificationTest.php +++ b/src/Tests/FileEntityFileTypeClassificationTest.php @@ -1,10 +1,5 @@ getFileType($image_file); $this->assertEqual($file_type['type'], 'undefined', t('The image file has an undefined file type.')); + // When editing files before cron is run the bundle should have correct + // value. + $account = $this->drupalCreateUser(['bypass file access']); + $this->drupalLogin($account); + $this->assertNotEqual($image_file->bundle(), 'image', 'The image file does not have correct bundle before loading it.'); + $this->drupalGet('file/' . $image_file->id() . '/edit'); + $this->drupalPostForm(NULL, [], t('Save')); + $image_file = File::load($image_file->id()); + $this->assertEqual($image_file->bundle(), 'image', 'The image file has correct bundle after load.'); + + $this->assertNotEqual($text_file->bundle(), 'document', 'The text file does not have correct bundle before loading it.'); + $this->drupalGet('file/' . $text_file->id() . '/inline-edit'); + $text_file = File::load($text_file->id()); + $this->assertEqual($text_file->bundle(), 'document', 'The text file has correct bundle after load.'); + // The classification queue is processed during cron runs. Run cron to // trigger the classification process. $this->cronRun(); @@ -85,4 +95,5 @@ class FileEntityFileTypeClassificationTest extends WebTestBase { $file_type = $this->getFileType($image_file); $this->assertEqual($file_type['type'], 'image', t('The image file was properly assigned the Image file type.')); } + }