Skip to content

Commit

Permalink
mod/resource: MDL-18691 allow custom resource types to specify their …
Browse files Browse the repository at this point in the history
…name in their own lang directory

Before this change, the full name of the resource type had to be stored in the "resource" namespace (for example in /mod/resource/lang/en_utf8/resource.php).

Now it can be put in the "resource_foo" namespace:

e.g. in /mod/resource/type/foo/lang/en_utf8/resource_foo.php:

<?php
  $string['resourcetypefoo'] = 'Link to a Foo Bar document';
?>
  • Loading branch information
fmarier committed Mar 27, 2009
1 parent a0b1f33 commit 7d6b6b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion mod/resource/lib.php
Expand Up @@ -597,7 +597,7 @@ function resource_get_types() {
$type->modclass = MOD_CLASS_RESOURCE;
$type->name = $resourcetype;
$type->type = "resource&amp;type=$resourcetype";
$type->typestr = get_string("resourcetype$resourcetype", 'resource');
$type->typestr = resource_get_name($resourcetype);
$types[] = $type;
}
}
Expand Down Expand Up @@ -713,4 +713,19 @@ function resource_delete_warning($course, $files) {
}
}

/**
* Returns the full name of the given resource type. The name can
* either be set at the resource type level or at the resource module
* level.
*
* @param string $type shortname (or directory name) of the resource type
*/
function resource_get_name($type) {
$name = get_string("resourcetype$type", "resource_$type");
if (substr($name, 0, 2) === '[[') {
$name = get_string("resourcetype$type", 'resource');
}
return $name;
}

?>
2 changes: 1 addition & 1 deletion mod/resource/mod_form.php
Expand Up @@ -40,7 +40,7 @@ function definition() {
// summary should be optional again MDL-9485
//$mform->addRule('summary', get_string('required'), 'required', null, 'client');

$mform->addElement('header', 'typedesc', get_string('resourcetype'.$type,'resource'));
$mform->addElement('header', 'typedesc', resource_get_name($type));
$this->_resinstance->setup_elements($mform);

$this->standard_coursemodule_elements(false);
Expand Down

0 comments on commit 7d6b6b1

Please sign in to comment.