diff --git a/src/Plugin/MediaEntity/Type/Twitter.php b/src/Plugin/MediaEntity/Type/Twitter.php index 97defcf..9d7d2dc 100644 --- a/src/Plugin/MediaEntity/Type/Twitter.php +++ b/src/Plugin/MediaEntity/Type/Twitter.php @@ -245,7 +245,7 @@ class Twitter extends MediaTypeBase { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $options = []; + $options = ['' => $this->t('- None -')]; $allowed_field_types = ['string', 'string_long', 'link']; /** @var \Drupal\media_entity\MediaBundleInterface $bundle */ $bundle = $form_state->getFormObject()->getEntity(); @@ -255,24 +255,25 @@ class Twitter extends MediaTypeBase { } } + // Select the source field. Only show when the bundle is not new, so there + // will potentially be fields to select. $form['source_field'] = array( '#type' => 'select', '#title' => $this->t('Field with source information'), '#description' => $this->t('Field on media entity that stores Twitter embed code or URL. You can create a bundle without selecting a value for this dropdown initially. This dropdown can be populated after adding fields to the bundle.'), '#default_value' => empty($this->configuration['source_field']) ? static::MEDIA_ENTITY_TWITTER_DEFAULT_FIELD_NAME : $this->configuration['source_field'], '#options' => $options, + '#access' => !$bundle->isNew(), ); // Add a checkbox to allow the field being created automatically on save. - if (empty($this->configuration['source_field'])) { - $form['create_source_field'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Create a source field automatically when saving this form.'), - '#description' => $this->t('If checked, a default field will be created and used as a source field. You can change this setting later.'), - '#default_value' => $this->configuration['create_source_field'], - '#access' => $bundle->isNew(), - ]; - } + $form['create_source_field'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Create a source field automatically when saving this form.'), + '#description' => $this->t('If checked, a default field will be created and used as a source field. If you uncheck the field, you will need to create a field and revisit this form later to select it.'), + '#default_value' => TRUE, + '#access' => $bundle->isNew(), + ]; $form['use_twitter_api'] = array( '#type' => 'select', @@ -568,8 +569,6 @@ class Twitter extends MediaTypeBase { $display->setComponent(static::MEDIA_ENTITY_TWITTER_DEFAULT_FIELD_NAME, [ 'type' => static::MEDIA_ENTITY_TWITTER_DEFAULT_FIELD_FORMATTER, ])->save(); - - // @TODO Evaluate if it's necessary to save the 'source_field' config value. } }