]> git.mjollnir.org Git - moodle.git/commitdiff
mod/resource: MDL-18691 allow custom resource types to specify their name in their...
authorfmarier <fmarier>
Fri, 27 Mar 2009 03:21:10 +0000 (03:21 +0000)
committerfmarier <fmarier>
Fri, 27 Mar 2009 03:21:10 +0000 (03:21 +0000)
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';
?>

mod/resource/lib.php
mod/resource/mod_form.php

index 6d3c299d3740bfb8542f90f9049d8ae8440de613..b14e78411e77844067d144b0c7e4c78c5c59b5b6 100644 (file)
@@ -526,7 +526,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;
         }
     }
@@ -763,4 +763,19 @@ function resource_supports($feature) {
     }
 }
 
+/**
+ * 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;
+}
+
 ?>
index 633ce29359c851ace9220bd0e97e4da19a1e49b6..7df033326af10b6ba0db8cab1b1183c943e19362 100644 (file)
@@ -44,7 +44,7 @@ class mod_resource_mod_form extends moodleform_mod {
         // 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(array('groups'=>false, 'groupmembersonly'=>true, 'gradecat'=>false));