createMediaTypeViaForm example

$source->submitConfigurationForm($form$form_state);
    $this->assertSame($expected$source->getConfiguration(), 'Submitted values were saved correctly.');
  }

  /** * Tests different display options for the source field. */
  public function testDifferentSourceFieldDisplays() {
    $id = 'test_different_displays';
    $field_name = 'field_media_different_display';

    $this->createMediaTypeViaForm($id$field_name);

    // Source field not in displays.     $display = \Drupal::service('entity_display.repository')->getViewDisplay('media', $id);
    $components = $display->getComponents();
    $this->assertArrayHasKey($field_name$components);
    $this->assertSame('entity_reference_entity_id', $components[$field_name]['type']);

    $display = \Drupal::service('entity_display.repository')->getFormDisplay('media', $id);
    $components = $display->getComponents();
    $this->assertArrayHasKey($field_name$components);
    $this->assertSame('entity_reference_autocomplete_tags', $components[$field_name]['type']);
  }
Home | Imprint | This part of the site doesn't use cookies.