I tried to create a node programatically with a media tag in the body (this was using Migrate BTW).

I used this code to create a Media tag which I then put in the body text:

  $data = array(
    'fid' => $file_entity_fid,
    'type' => 'media',
    'view_mode' => $view_mode,
    'link_text' => NULL,
    'attributes' => $attributes,
  );

  return '[[' . drupal_json_encode($data) . ']]';

This works up to a point, but when $attributes is an empty array, the view mode is ignored.

If I then edit the node in Drupal and re-save it, the view mode then applies.

This seems to me to be caused by the same thing that causes #2422153: View mode classes accumulate when changing image view mode -- it appears that the CSS classes for view modes are added to the tag, rather than deduced from the view mode.

Comments

joachim created an issue. See original summary.

Chris Matthews’s picture

Status: Active » Closed (outdated)

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team