Issue #3171743 by chr.fritsch, paulocs, Berdir, phenaproxima: Not possible to overwrite the upload forms for media library
parent
6d1b1689ea
commit
afba4ff18c
|
@ -84,12 +84,22 @@ function media_library_help($route_name, RouteMatchInterface $route_match) {
|
|||
* Implements hook_media_source_info_alter().
|
||||
*/
|
||||
function media_library_media_source_info_alter(array &$sources) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
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
|
|
@ -0,0 +1,12 @@
|
|||
<?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;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?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\KernelTests\KernelTestBase;
|
|||
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 @@ class MediaLibraryAddFormTest extends KernelTestBase {
|
|||
\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']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue