diff --git a/config/schema/media_entity_twitter.schema.yml b/config/schema/media_entity_twitter.schema.yml index 90c364b..f3c8ad4 100644 --- a/config/schema/media_entity_twitter.schema.yml +++ b/config/schema/media_entity_twitter.schema.yml @@ -13,6 +13,9 @@ media_entity.bundle.type.twitter: source_field: type: string label: 'Field with embed code/URL' + create_source_field: + type: boolean + label: 'Whether to automatically create a source field on bundle creation or not' use_twitter_api: type: boolean label: 'Whether to use twitter api or not' diff --git a/src/Plugin/MediaEntity/Type/Twitter.php b/src/Plugin/MediaEntity/Type/Twitter.php index ac477f4..1599387 100644 --- a/src/Plugin/MediaEntity/Type/Twitter.php +++ b/src/Plugin/MediaEntity/Type/Twitter.php @@ -96,6 +96,7 @@ class Twitter extends MediaTypeBase { public function defaultConfiguration() { return [ 'use_twitter_api' => FALSE, + 'create_source_field' => TRUE, ]; } @@ -215,9 +216,19 @@ class Twitter extends MediaTypeBase { '#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']) ? NULL : $this->configuration['source_field'], '#options' => $options, - '#weight' => -10, ); + // 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['use_twitter_api'] = array( '#type' => 'select', '#title' => $this->t('Whether to use Twitter api to fetch tweets or not.'),