use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Entity\EntityFieldManagerInterface;
* Media source plugin manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* Entity field manager service.
*/
* Media source plugin manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* Entity field manager service.
*/
$form['source_dependent']['source'] = [
'#type' => 'select',
'#title' => $this->t('Media source'),
'#default_value' => $source ? $source->getPluginId() : NULL,
'#options' => $options,
$form['source_dependent']['source'] = [
'#type' => 'select',
'#title' => $this->t('Media source'),
'#default_value' => $source ? $source->getPluginId() : NULL,
'#options' => $options,
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Let the selected plugin validate its settings.
$this->entity->getSource()->validateConfigurationForm($form['source_dependent']['source_configuration'], $this->getSourceSubFormState($form, $form_state));
}
// Let the selected plugin validate its settings.
$this->entity->getSource()->validateConfigurationForm($form['source_dependent']['source_configuration'], $this->getSourceSubFormState($form, $form_state));
}
->setStatus((bool) $form_state->getValue(['options', 'status']))
->setNewRevision((bool) $form_state->getValue(['options', 'new_revision']));
->setStatus((bool) $form_state->getValue(['options', 'status']))
->setNewRevision((bool) $form_state->getValue(['options', 'new_revision']));
// Let the selected plugin save its settings.
$this->entity->getSource()->submitConfigurationForm($form['source_dependent']['source_configuration'], $this->getSourceSubFormState($form, $form_state));
}
// Let the selected plugin save its settings.
$this->entity->getSource()->submitConfigurationForm($form['source_dependent']['source_configuration'], $this->getSourceSubFormState($form, $form_state));
}
// @todo Replace entity_get_form_display() when #2367933 is done.
// https://www.drupal.org/node/2872159.
// @todo Replace entity_get_form_display() when #2367933 is done.
// https://www.drupal.org/node/2872159.
- entity_get_form_display('media', $media_type->id(), 'default')
- ->setComponent($field_name, $component)
- ->save();
+ $display = entity_get_form_display('media', $media_type->id(), 'default');
+ $source->prepareFormDisplay($media_type, $display);
+ $display->save();
- entity_get_display('media', $media_type->id(), 'default')
- ->setComponent($field_name, $component)
- ->save();
+ $display = entity_get_display('media', $media_type->id(), 'default');
+ $source->prepareViewDisplay($media_type, $display);
+ $display->save();