Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #2
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedClosing 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