diff --git a/core/modules/media/src/Entity/MediaType.php b/core/modules/media/src/Entity/MediaType.php index da65b3a..7ea70a8 100644 --- a/core/modules/media/src/Entity/MediaType.php +++ b/core/modules/media/src/Entity/MediaType.php @@ -226,21 +226,18 @@ public function setNewRevision($new_revision) { * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { - parent::preSave($storage); - // If the handler uses a source field, we'll need to store its name before // saving. We'd need to double-save if we did this in postSave(). $handler = $this->getHandler(); if ($handler instanceof SourceFieldInterface) { - $storage = $handler->getSourceField($this)->getFieldStorageDefinition(); + $field_storage = $handler->getSourceField($this)->getFieldStorageDefinition(); // If the field storage is a new (unsaved) config entity, save it. - if ($storage instanceof FieldStorageConfigInterface && $storage->isNew()) { - $storage->save(); + if ($field_storage instanceof FieldStorageConfigInterface && $field_storage->isNew()) { + $field_storage->save(); } - // We need to save handler configuration that have just changed above and - // won't be included otherwise. - $this->handler_configuration = $handler->getConfiguration(); } + + parent::preSave($storage); } /** diff --git a/core/modules/media/src/MediaHandlerBase.php b/core/modules/media/src/MediaHandlerBase.php index 14d8636..7a25b0b 100644 --- a/core/modules/media/src/MediaHandlerBase.php +++ b/core/modules/media/src/MediaHandlerBase.php @@ -104,7 +104,7 @@ public function getConfiguration() { */ public function defaultConfiguration() { return [ - 'source_field' => NULL, + 'source_field' => '', ]; } @@ -132,11 +132,7 @@ public function attachConstraints(MediaInterface $media) { * {@inheritdoc} */ public function calculateDependencies() { - $dependencies = []; - if ($this->configuration['source_field']) { - $dependencies['config'][] = 'field.storage.' . $this->configuration['source_field']; - } - return $dependencies; + return []; } /** @@ -193,7 +189,11 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->setConfiguration($form_state->getValues()); + foreach($form_state->getValues() as $config_key => $config_value) { + if (isset($this->configuration[$config_key])) { + $this->configuration[$config_key] = $config_value; + } + } } /** diff --git a/core/modules/media/src/MediaTypeForm.php b/core/modules/media/src/MediaTypeForm.php index a1d88f2..0542917 100644 --- a/core/modules/media/src/MediaTypeForm.php +++ b/core/modules/media/src/MediaTypeForm.php @@ -75,11 +75,10 @@ public function ajaxHandlerData(array $form, FormStateInterface $form_state) { */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - $form_state->set('bundle', $this->entity->id()); // Handler is not set when the entity is initially created. /** @var \Drupal\media\MediaHandlerInterface $handler */ - $handler = $this->entity->get('handler') ? $handler = $this->entity->getHandler() : NULL; + $handler = $this->entity->get('handler') ? $this->entity->getHandler() : NULL; if ($this->operation === 'add') { $form['#title'] = $this->t('Add media type');