X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fmedia%2Fsrc%2FMediaTypeForm.php;fp=web%2Fcore%2Fmodules%2Fmedia%2Fsrc%2FMediaTypeForm.php;h=fb4915fa3d0c5a93162a7a60dd433841e5e82603;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=7766af2e567d63be3dd65acd453ecaf0cd21d6ba;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/media/src/MediaTypeForm.php b/web/core/modules/media/src/MediaTypeForm.php index 7766af2e5..fb4915fa3 100644 --- a/web/core/modules/media/src/MediaTypeForm.php +++ b/web/core/modules/media/src/MediaTypeForm.php @@ -2,6 +2,7 @@ namespace Drupal\media; +use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Entity\EntityFieldManagerInterface; @@ -23,7 +24,7 @@ class MediaTypeForm extends EntityForm { /** * Media source plugin manager. * - * @var \Drupal\media\MediaSourceManager + * @var \Drupal\Component\Plugin\PluginManagerInterface */ protected $sourceManager; @@ -37,12 +38,12 @@ class MediaTypeForm extends EntityForm { /** * Constructs a new class instance. * - * @param \Drupal\media\MediaSourceManager $source_manager + * @param \Drupal\Component\Plugin\PluginManagerInterface $source_manager * Media source plugin manager. * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager * Entity field manager service. */ - public function __construct(MediaSourceManager $source_manager, EntityFieldManagerInterface $entity_field_manager) { + public function __construct(PluginManagerInterface $source_manager, EntityFieldManagerInterface $entity_field_manager) { $this->sourceManager = $source_manager; $this->entityFieldManager = $entity_field_manager; } @@ -118,7 +119,7 @@ class MediaTypeForm extends EntityForm { '#attributes' => ['id' => 'source-dependent'], ]; - if ($source) { + if (!$this->entity->isNew()) { $source_description = $this->t('The media source cannot be changed after the media type is created.'); } else { @@ -131,23 +132,12 @@ class MediaTypeForm extends EntityForm { '#options' => $options, '#description' => $source_description, '#ajax' => ['callback' => '::ajaxHandlerData'], - // Rebuilding the form as part of the AJAX request is a workaround to - // enforce machine_name validation. - // @todo This was added as part of #2932226 and it should be removed once - // https://www.drupal.org/project/drupal/issues/2557299 solves it in a - // more generic way. - '#executes_submit_callback' => TRUE, - '#submit' => [[static::class, 'rebuildSubmit']], '#required' => TRUE, // Once the media type is created, its source plugin cannot be changed // anymore. - '#disabled' => !empty($source), + '#disabled' => !$this->entity->isNew(), ]; - if (!$source) { - $form['type']['#empty_option'] = $this->t('- Select media source -'); - } - if ($source) { // Media source plugin configuration. $form['source_dependent']['source_configuration'] = [ @@ -240,18 +230,6 @@ class MediaTypeForm extends EntityForm { return $form; } - /** - * Form submission handler to rebuild the form on select submit. - * - * @param array $form - * Full form array. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * Current form state. - */ - public static function rebuildSubmit(array &$form, FormStateInterface $form_state) { - $form_state->setRebuild(); - } - /** * Prepares workflow options to be used in the 'checkboxes' form element. * @@ -373,10 +351,10 @@ class MediaTypeForm extends EntityForm { $t_args = ['%name' => $media_type->label()]; if ($status === SAVED_UPDATED) { - drupal_set_message($this->t('The media type %name has been updated.', $t_args)); + $this->messenger()->addStatus($this->t('The media type %name has been updated.', $t_args)); } elseif ($status === SAVED_NEW) { - drupal_set_message($this->t('The media type %name has been added.', $t_args)); + $this->messenger()->addStatus($this->t('The media type %name has been added.', $t_args)); $this->logger('media')->notice('Added media type %name.', $t_args); }