Add new comment
Drupal Tutorial - Creating an embedded video or audio player for a link field
Use Case:
Objective
- As an administrator or a content editor you want to add a link to your content type.
- To the end user you want the link to be displayed as an embedded player.
Example of Adminstrative Workflow
- Creating a new field
- Add the url of the media file.
- The end result. An embedded audio player
Question
How do we do this?
Enter the custom formatters module
With the custom formatters module you can create custom displays of the link
- After you downloaded and enabled the module goto Admin -> Structure -> Formatter. Then click add. Note: you may need to clear the cache to see the Formatters menu button
- Under “Field type(s)” -> Enter link_field into the text field
- Under “Formatter” I've added this code below. Note: if you are copying and pasting, do not include the <?php ?> tags.
<!--?php
foreach ($variables['#items'] as $item) {
$url = $item['display_url'];
print "<div class='embedded-item'-->"; print "
"; print "
"; print ""; } ?>
- Now goto Admin -> Structure -> Content type -> [type] -> Manage Display
And viola! You now have a podbean player embedded on your site. If you want another player, embed its code into the custom formatter field.