doTestCreateMediaType example

$source_field_id = 'field_media_file';
    $provided_fields = [
      File::METADATA_ATTRIBUTE_NAME,
      File::METADATA_ATTRIBUTE_SIZE,
      File::METADATA_ATTRIBUTE_MIME,
    ];

    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $this->doTestCreateMediaType($media_type_id, 'file', $provided_fields);

    // Create custom fields for the media type to store metadata attributes.     $fields = [
      'field_string_file_size' => 'string',
      'field_string_mime_type' => 'string',
    ];
    $this->createMediaTypeFields($fields$media_type_id);

    // Hide the name field widget to test default name generation.     $this->hideMediaTypeFieldWidget('name', $media_type_id);

    
'thumbnail_height',
      'url',
      'width',
      'height',
      'html',
    ];

    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $this->doTestCreateMediaType($media_type_id, 'oembed:video', $provided_fields);

    // Create custom fields for the media type to store metadata attributes.     $fields = [
      'field_string_width' => 'string',
      'field_string_height' => 'string',
      'field_string_author_name' => 'string',
    ];
    $this->createMediaTypeFields($fields$media_type_id);

    // Hide the name field widget to test default name generation.     $this->hideMediaTypeFieldWidget('name', $media_type_id);

    
/** * Check the Audio source functionality. */
  public function testAudioTypeCreation() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    $source_id = 'audio_file';
    $type_name = 'audio_type';
    $field_name = 'field_media_' . $source_id;
    $this->doTestCreateMediaType($type_name$source_id);

    // Check that the source field was created with the correct settings.     $storage = FieldStorageConfig::load("media.$field_name");
    $this->assertInstanceOf(FieldStorageConfig::class$storage);
    $field = FieldConfig::load("media.$type_name.$field_name");
    $this->assertInstanceOf(FieldConfig::class$field);
    $this->assertSame('mp3 wav aac', FieldConfig::load("media.$type_name.$field_name")->get('settings')['file_extensions']);

    // Check that the display holds the correct formatter configuration.     $display = EntityViewDisplay::load("media.$type_name.default");
    $this->assertInstanceOf(EntityViewDisplay::class$display);
    
$media_type_id = 'test_media_image_type';
    $source_field_id = 'field_media_image';
    $provided_fields = [
      Image::METADATA_ATTRIBUTE_WIDTH,
      Image::METADATA_ATTRIBUTE_HEIGHT,
    ];

    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $this->doTestCreateMediaType($media_type_id, 'image', $provided_fields);

    // Create custom fields for the media type to store metadata attributes.     $fields = [
      'field_string_width' => 'string',
      'field_string_height' => 'string',
    ];
    $this->createMediaTypeFields($fields$media_type_id);

    // Hide the name field widget to test default name generation.     $this->hideMediaTypeFieldWidget('name', $media_type_id);

    
Home | Imprint | This part of the site doesn't use cookies.