prepareFormDisplay example

parent::prepareViewDisplay($type$display);
    $source_name = $this->getSourceFieldDefinition($type)->getName();
    $source_component = $display->getComponent($source_name) ?: [];
    $source_component['type'] = 'entity_reference_entity_id';
    $display->setComponent($source_name$source_component);
  }

  /** * {@inheritdoc} */
  public function prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display) {
    parent::prepareFormDisplay($type$display);
    $source_name = $this->getSourceFieldDefinition($type)->getName();
    $source_component = $display->getComponent($source_name) ?: [];
    $source_component['type'] = 'entity_reference_autocomplete_tags';
    $display->setComponent($source_name$source_component);
  }

  /** * {@inheritdoc} */
  protected function getSourceFieldName() {
    return 'field_media_different_display';
  }
$this->assertSame(SAVED_NEW, $media_type->save());

    // The media type form creates a source field if it does not exist yet. The     // same must be done in a kernel test, since it does not use that form.     // @see \Drupal\media\MediaTypeForm::save()     $source_field->getFieldStorageDefinition()->save();
    // The source field storage has been created, now the field can be saved.     $source_field->save();

    // Add the source field to the form display for the media type.     $form_display = \Drupal::service('entity_display.repository')->getFormDisplay('media', $media_type->id(), 'default');
    $source->prepareFormDisplay($media_type$form_display);
    $form_display->save();

    return $media_type;
  }

}
public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
    $display->setComponent($this->getSourceFieldDefinition($type)->getName()[
      'type' => 'oembed',
      'label' => 'visually_hidden',
    ]);
  }

  /** * {@inheritdoc} */
  public function prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display) {
    parent::prepareFormDisplay($type$display);
    $source_field = $this->getSourceFieldDefinition($type)->getName();

    $display->setComponent($source_field[
      'type' => 'oembed_textfield',
      'weight' => $display->getComponent($source_field)['weight'],
    ]);
    $display->removeComponent('name');
  }

  /** * {@inheritdoc} */
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
      $storage = $source_field->getFieldStorageDefinition();
      if ($storage->isNew()) {
        $storage->save();
      }
      $source_field->save();

      // Add the new field to the default form and view displays for this       // media type.       if ($source_field->isDisplayConfigurable('form')) {
        $display = $this->entityDisplayRepository->getFormDisplay('media', $media_type->id());
        $source->prepareFormDisplay($media_type$display);
        $display->save();
      }
      if ($source_field->isDisplayConfigurable('view')) {
        $display = $this->entityDisplayRepository->getViewDisplay('media', $media_type->id());

        // Remove all default components.         foreach (array_keys($display->getComponents()) as $name) {
          $display->removeComponent($name);
        }
        $source->prepareViewDisplay($media_type$display);
        $display->save();
      }
Home | Imprint | This part of the site doesn't use cookies.