You are here

protected function MediaBundleForm::copyFormValuesToEntity in Media entity 8

Copies top-level form values to entity properties

This should not change existing entity properties that are not being edited by this form.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the current form should operate upon.

array $form: A nested array of form elements comprising the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides EntityForm::copyFormValuesToEntity

File

src/MediaBundleForm.php, line 335

Class

MediaBundleForm
Form controller for node type forms.

Namespace

Drupal\media_entity

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
  $configuration = $form_state
    ->getValue('type_configuration');

  // Store previous plugin config.
  $plugin = $entity
    ->getType()
    ->getPluginId();
  $this->configurableInstances[$plugin]['plugin_config'] = empty($configuration[$plugin]) ? [] : $configuration[$plugin];

  /** @var \Drupal\media_entity\MediaBundleInterface $entity */
  parent::copyFormValuesToEntity($entity, $form, $form_state);

  // Use type configuration for the plugin that was chosen.
  $plugin = $entity
    ->getType()
    ->getPluginId();
  $plugin_configuration = empty($configuration[$plugin]) ? [] : $configuration[$plugin];
  $entity
    ->set('type_configuration', $plugin_configuration);

  // Save field mapping.
  $entity->field_map = array_filter($form_state
    ->getValue('field_mapping', []), function ($item) {
    return $item != '_none';
  });
}