A bit confusing because it is rare for me to attempt any coding.
For this example I will pretend the content type is "Article".
First go to manage fields, and add a new field of list (text) to your content type. Let's say the possible values are "video" and "image". So For allowed values list, put
image|image
video|video
In /themes/your_theme_name/your_theme_name.theme add the following
/**
* Implements hook_form_FORM_ID_alter().
*/
function your_theme_name_form_node_article_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) {
$form['field_image']['#states'] = [
'visible' => [
'select[name="field_select"]' => ['value' => 'image']
]
];
$form['field_video']['#states'] = [
'visible' => [
'select[name="field_select"]' => ['value' => 'video']
]
];
}
- Replace
your_theme_name
with your actual theme name. - Replace
article
with your actual content type name. - Replace
field_select
with the machine name of your select field. - Replace
field_image
with the machine name of your image field. - Replace
field_video
with the machine name of your video field.
Lastly, clear and flush all cache to see changes.