Skip to content
Browse files

MDL-38166 mod_data Add option to open url in a new window

  • Loading branch information...
1 parent 8673a98 commit 6f07bf766b2b314b8f1b1b5fccf8ea7ec3f9efaf @andrewnicols andrewnicols committed Mar 2, 2013
Showing with 19 additions and 8 deletions.
  1. +10 −4 mod/data/field/url/field.class.php
  2. +1 −0 mod/data/field/url/lang/en/datafield_url.php
  3. +8 −4 mod/data/field/url/mod.html
View
14 mod/data/field/url/field.class.php
@@ -109,11 +109,17 @@ function display_browse_field($recordid, $template) {
}
if ($this->field->param1) {
// param1 defines whether we want to autolink the url.
- if (!empty($text)) {
- $str = '<a href="'.$url.'">'.$text.'</a>';
- } else {
- $str = '<a href="'.$url.'">'.$url.'</a>';
+ $attributes = array();
+ if ($this->field->param3) {
+ // param3 defines whether this URL should open in a new window.
+ $attributes['target'] = '_blank';
}
+
+ if (empty($text)) {
+ $text = $url;
+ }
+
+ $str = html_writer::link($url, $text, $attributes);
} else {
$str = $url;
}
View
1 mod/data/field/url/lang/en/datafield_url.php
@@ -25,3 +25,4 @@
*/
$string['pluginname'] = 'URL';
+$string['openlinkinnewwindow'] = 'Open link in new window';
View
12 mod/data/field/url/mod.html
@@ -8,11 +8,15 @@
<td class="c1"><input class="fielddescription" type="text" name="description" id="description" value="<?php p($this->field->description);?>" /></td>
</tr>
<tr>
- <td class="c0"><label for="forcelinkname"><?php echo get_string('forcelinkname', 'data'); ?></label></td>
- <td class="c1"><input class="forcelinkname" type="text" name="param2" id="forcelinkname" value="<?php p($this->field->param2);?>" /></td>
- </tr>
- <tr>
<td class="c0"><label for="param1"><?php echo get_string('autolinkurl', 'data') ?></label></td>
<td class="c1"><input type="checkbox" name="param1" id="param1" <?php if($this->field->param1) {echo 'checked="checked"';} ?> value="1" /></td>
</tr>
+ <tr>
+ <td class="c0"><label for="param3"><?php echo get_string('openlinkinnewwindow', 'datafield_url') ?></label></td>
+ <td class="c1"><input type="checkbox" name="param3" id="param3" <?php if($this->field->param3) {echo 'checked="checked"';} ?> value="1" /></td>
+ </tr>
+ <tr>
+ <td class="c0"><label for="forcelinkname"><?php echo get_string('forcelinkname', 'data'); ?></label></td>
+ <td class="c1"><input class="forcelinkname" type="text" name="param2" id="forcelinkname" value="<?php p($this->field->param2);?>" /></td>
+ </tr>
</table>

0 comments on commit 6f07bf7

Please sign in to comment.
Something went wrong with that request. Please try again.