1

i want to display the media description available in the file field of a media ( media of type video, audio, image, etc...), it is an option to activate:

Enable Description field

The description field allows users to enter a description about the uploaded file.

i already print other fields that i want in the media twig template, but i can not find the value of that "description" field attribute, because it's not a field, but some sort of attribute of the file field.

1 Answer 1

1

I got the media description in the preprocess

function template_preprocess_media(array &$variables) {

  $bundle = $media->Bundle();

  if($bundle == 'file') {
    $field_media_file = $variables['content']["field_media_file"];
 
    if($field_media_file[0]["#description"]){
      $desc = $field_media_file[0]["#description"];
    } else{
      $desc = $variables['name'];
    }
    $variables['description'] = $desc;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.