Digging the form_state I found the user submitted values for embedded media entites lies at form state storage. My validation code now looks like
/**
* Implememts hook_form_alter().
*/
function mymodulename_form_alter(&$form, \Drupal \Core\Form\FormStateInterface $form_state, $form_id) {
$operative_form = array(
'my_node_add_form',
'my_node_edit_form'
);
if (!in_array($form_id, $operative_form)) {
return;
}
$form['#validate'][] = '_mymodulename_validate_element_node_form';
}
/**
* Custom validation handler for EDP.
*/
function _mymodulename_validate_element_node_form($form, $form_state) {
$form_storage = $form_state->getStorage();
$form_storage_embed_entities = $form_storage['inline_entity_form'];
foreach ($form_storage_embed_entities as $key => $value) {
$media_entities = $value['entities'];
foreach ($media_entities as $media_entity) {
if ($media_entity['entity'] instanceof \Drupal\Core\Entity\EntityInterface) {
if ($media_entity['entity']->getEntityTypeId() == 'media') {
$asset_type[$media_entity['entity']->field_asset_type->value] = $media_entity['entity']->field_asset_type->value;
}
}
if (count($asset_type) > 1) {
// early bail.
break;
}
}
// Validation condition goes here.
if ($validation_condition) {
$form_state->setErrorByName('field_asset', t('Did you try turning it on and off.'));
}
}
}