Unverified Commit 3dfa5601 authored by alexpott's avatar alexpott

Issue #3171743 by chr.fritsch, paulocs, Berdir, phenaproxima: Not possible to...

Issue #3171743 by chr.fritsch, paulocs, Berdir, phenaproxima: Not possible to overwrite the upload forms for media library

(cherry picked from commit afba4ff1)
parent b8eca233
......@@ -84,11 +84,21 @@ function media_library_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_media_source_info_alter().
*/
function media_library_media_source_info_alter(array &$sources) {
$sources['audio_file']['forms']['media_library_add'] = FileUploadForm::class;
$sources['file']['forms']['media_library_add'] = FileUploadForm::class;
$sources['image']['forms']['media_library_add'] = FileUploadForm::class;
$sources['video_file']['forms']['media_library_add'] = FileUploadForm::class;
$sources['oembed:video']['forms']['media_library_add'] = OEmbedForm::class;
if (empty($sources['audio_file']['forms']['media_library_add'])) {
$sources['audio_file']['forms']['media_library_add'] = FileUploadForm::class;
}
if (empty($sources['file']['forms']['media_library_add'])) {
$sources['file']['forms']['media_library_add'] = FileUploadForm::class;
}
if (empty($sources['image']['forms']['media_library_add'])) {
$sources['image']['forms']['media_library_add'] = FileUploadForm::class;
}
if (empty($sources['video_file']['forms']['media_library_add'])) {
$sources['video_file']['forms']['media_library_add'] = FileUploadForm::class;
}
if (empty($sources['oembed:video']['forms']['media_library_add'])) {
$sources['oembed:video']['forms']['media_library_add'] = OEmbedForm::class;
}
}
/**
......
name: 'Media Library Form Overwrite test'
type: module
description: 'Test module for Media Library.'
package: Testing
dependencies:
- drupal:image
- drupal:media_library
- drupal:menu_ui
- drupal:node
- drupal:path
<?php
/**
* @file
* Contains.
*/
use Drupal\media_library_form_overwrite_test\Form\TestAddForm;
function media_library_form_overwrite_test_media_source_info_alter(array &$sources) {
$sources['image']['forms']['media_library_add'] = TestAddForm::class;
}
<?php
namespace Drupal\media_library_form_overwrite_test\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\media_library\Form\AddFormBase;
/**
* Test add form.
*/
class TestAddForm extends AddFormBase {
/**
* {@inheritdoc}
*/
protected function buildInputElement(array $form, FormStateInterface $form_state) {
return [];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'test_add_form';
}
}
......@@ -7,6 +7,7 @@
use Drupal\media_library\Form\FileUploadForm;
use Drupal\media_library\Form\OEmbedForm;
use Drupal\media_library\MediaLibraryState;
use Drupal\media_library_form_overwrite_test\Form\TestAddForm;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
......@@ -137,4 +138,19 @@ public function testSelectedTypeValidation() {
\Drupal::formBuilder()->buildForm(FileUploadForm::class, $form_state);
}
/**
* Tests overwriting of the add form.
*/
public function testDifferentAddForm() {
$this->enableModules(['media_library_form_overwrite_test']);
$entity_type_manager = \Drupal::entityTypeManager();
$image = $entity_type_manager->getStorage('media_type')->load('image');
$image_source_definition = $image->getSource()->getPluginDefinition();
// Assert the overwritten form class is set to the media source.
$this->assertSame(TestAddForm::class, $image_source_definition['forms']['media_library_add']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment