changeMediaReferenceFieldLinkType example

->save();

    // Alter the form display.     $this->container->get('entity_display.repository')
      ->getFormDisplay('node', 'article')
      ->setComponent('field_media_reference', [
        'type' => 'entity_reference_autocomplete',
      ])
      ->save();

    // Change the image thumbnail to point into the media.     $this->changeMediaReferenceFieldLinkType('media');

    // Create and upload a file to the media.     $file = File::create([
      'uri' => current($this->getTestFiles('image'))->uri,
    ]);
    $file->save();
    $mediaImage = Media::create([
      'bundle' => 'image',
      'name' => 'Test image',
      'field_media_image' => $file->id(),
    ]);
    
Home | Imprint | This part of the site doesn't use cookies.