Skip to content

Commit

Permalink
Renaming option type to tag to avoid potential conflict in future…
Browse files Browse the repository at this point in the history
… with html attribute.
  • Loading branch information
ADmad committed Feb 10, 2012
1 parent 7a42290 commit e2b273e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -1725,7 +1725,7 @@ public function testMedia() {
);
$this->assertTags($result, $expected);

$result = $this->Html->media('video.ogv', array('type' => 'video'));
$result = $this->Html->media('video.ogv', array('tag' => 'video'));
$expected = array('video' => array('src' => 'files/video.ogv'), '/video');
$this->assertTags($result, $expected);

Expand Down
32 changes: 18 additions & 14 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -991,9 +991,9 @@ public function para($class, $text, $options = array()) {
* Using multiple video files:
*
* {{{
* echo $this->Html->video(
* echo $this->Html->media(
* array('video.mp4', array('src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'")),
* array('type' => 'video', 'autoplay')
* array('tag' => 'video', 'autoplay')
* );
* }}}
*
Expand All @@ -1008,24 +1008,28 @@ public function para($class, $text, $options = array()) {
*
* ### Options
*
* - `type` Type of media element to generate, valid values are "audio" or "video".
* If type is not provided media type is guessed based on file's mime type.
* - `tag` Type of media element to generate, either "audio" or "video".
* If tag is not provided it's guessed based on file's mime type.
* - `text` Text to include inside the audio/video tag
* - `pathPrefix` Path prefix to use for relative urls, defaults to 'files/'
* - `fullBase` If provided the src attribute will get a full address including domain name
*
* @param string|array $path Path to the video file, relative to the webroot/{$options['pathPrefix']} directory.
* Or an array where each item itself can be a path string or an associate array containing keys `src` and `type`
* @param array $options Array of HTML attributes, and special options above.
* @return string Generated video tag
* @return string Generated media element
*/
public function media($path, $options = array()) {
$options += array('type' => null, 'pathPrefix' => 'files/', 'text' => '');
$options += array(
'tag' => null,
'pathPrefix' => 'files/',
'text' => ''
);

if (!empty($options['type'])) {
$type = $options['type'];
if (!empty($options['tag'])) {
$tag = $options['tag'];
} else {
$type = null;
$tag = null;
}

if (is_array($path)) {
Expand Down Expand Up @@ -1053,16 +1057,16 @@ public function media($path, $options = array()) {
$options['src'] = $this->assetUrl($path, $options);
}

if ($type === null) {
if ($tag === null) {
if (is_array($path)) {
$mimeType = $path[0]['type'];
} else {
$mimeType = $this->response->getMimeType(pathinfo($path, PATHINFO_EXTENSION));
}
if (preg_match('#^video/#', $mimeType)) {
$type = 'video';
$tag = 'video';
} else {
$type = 'audio';
$tag = 'audio';
}
}

Expand All @@ -1072,12 +1076,12 @@ public function media($path, $options = array()) {
$text = $options['text'];

$options = array_diff_key($options, array(
'type' => '',
'tag' => '',
'fullBase' => '',
'pathPrefix' => '',
'text' => ''
));
return $this->tag($type, $text, $options);
return $this->tag($tag, $text, $options);
}

/**
Expand Down

0 comments on commit e2b273e

Please sign in to comment.