MDL-84948 core: require plugin types always define lang strings.
This is consistent with subplugin behaviour since 36d842e0.
Co-authored-by: Daniel Ziegenberg <daniel@ziegenberg.at>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
issueNumber: MDL-84948
|
||||
notes:
|
||||
core:
|
||||
- message: >-
|
||||
The `core_plugin_manager::plugintype_name[_plural]` methods now require
|
||||
language strings for plugin types always be defined via `type_<type>`
|
||||
and `type_<type>_plural` language strings
|
||||
type: changed
|
||||
@@ -629,44 +629,36 @@ class plugin_manager {
|
||||
/**
|
||||
* Returns a localized name of a plugin typed in singular form
|
||||
*
|
||||
* Most plugin types define their names in core_plugin lang file. In case of subplugins,
|
||||
* we try to ask the parent plugin for the name. In the worst case, we will return
|
||||
* the value of the passed $type parameter.
|
||||
* Plugin types define their names in core_plugin lang file. In the case of subplugins,
|
||||
* we ask the parent plugin for the name
|
||||
*
|
||||
* @param string $type the type of the plugin, e.g. mod or workshopform
|
||||
* @return string
|
||||
*/
|
||||
public function plugintype_name($type) {
|
||||
if (get_string_manager()->string_exists('type_' . $type, 'core_plugin')) {
|
||||
// For most plugin types, their names are defined in core_plugin lang file.
|
||||
return get_string('type_' . $type, 'core_plugin');
|
||||
} else if ($parent = $this->get_parent_of_subplugin($type)) {
|
||||
if ($parent = $this->get_parent_of_subplugin($type, true)) {
|
||||
// If this is a subplugin, try to ask the parent plugin for the name.
|
||||
return $this->plugin_name($parent) . ' / ' . get_string('subplugintype_' . $type, $parent);
|
||||
} else {
|
||||
return $type;
|
||||
return get_string('type_' . $type, 'core_plugin');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a localized name of a plugin type in plural form
|
||||
*
|
||||
* Most plugin types define their names in core_plugin lang file. In case of subplugins,
|
||||
* we try to ask the parent plugin for the name. In the worst case, we will return
|
||||
* the value of the passed $type parameter.
|
||||
* Plugin types define their names in core_plugin lang file. In the case of subplugins,
|
||||
* we ask the parent plugin for the name
|
||||
*
|
||||
* @param string $type the type of the plugin, e.g. mod or workshopform
|
||||
* @return string
|
||||
*/
|
||||
public function plugintype_name_plural($type) {
|
||||
if (get_string_manager()->string_exists('type_' . $type . '_plural', 'core_plugin')) {
|
||||
// For most plugin types, their names are defined in core_plugin lang file.
|
||||
return get_string('type_' . $type . '_plural', 'core_plugin');
|
||||
} else if ($parent = $this->get_parent_of_subplugin($type)) {
|
||||
if ($parent = $this->get_parent_of_subplugin($type, true)) {
|
||||
// If this is a subplugin, try to ask the parent plugin for the name.
|
||||
return $this->plugin_name($parent) . ' / ' . get_string('subplugintype_' . $type . '_plural', $parent);
|
||||
} else {
|
||||
return $type;
|
||||
return get_string('type_' . $type . '_plural', 'core_plugin');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -26,3 +26,5 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$string['fullfeatured:fakecapability'] = 'Fullfeatured capability description';
|
||||
$string['pluginname'] = 'Fake full featured plugin';
|
||||
$string['subplugintype_fulldeprecatedsubtype'] = 'Full Sub Fake';
|
||||
$string['subplugintype_fulldeprecatedsubtype_plural'] = 'Full Sub Fakes';
|
||||
|
||||
@@ -847,9 +847,13 @@ final class plugin_manager_test extends \advanced_testcase {
|
||||
$this->assertEquals('fake_fullfeatured', $uninstallurl->param('uninstall'));
|
||||
|
||||
// Strings are supported for deprecated plugins.
|
||||
$stringmanager = $this->get_mocked_string_manager();
|
||||
$stringmanager->mock_string('type_fake', 'core_plugin', 'Fake');
|
||||
$stringmanager->mock_string('type_fake_plural', 'core_plugin', 'Fakes');
|
||||
|
||||
$this->assertEquals('Fake full featured plugin', $pluginman->plugin_name('fake_fullfeatured'));
|
||||
$this->assertEquals('fake', $pluginman->plugintype_name('fake'));
|
||||
$this->assertEquals('fake', $pluginman->plugintype_name_plural('fake'));
|
||||
$this->assertEquals('Fake', $pluginman->plugintype_name('fake'));
|
||||
$this->assertEquals('Fakes', $pluginman->plugintype_name_plural('fake'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -920,6 +924,13 @@ final class plugin_manager_test extends \advanced_testcase {
|
||||
$uninstallurl = $pluginman->get_uninstall_url('fulldeprecatedsubtype_test');
|
||||
$this->assertInstanceOf(\moodle_url::class, $uninstallurl);
|
||||
$this->assertEquals('fulldeprecatedsubtype_test', $uninstallurl->param('uninstall'));
|
||||
|
||||
// Strings are supported for deprecated subplugins.
|
||||
$this->assertEquals('Fake full featured plugin / Full Sub Fake', $pluginman->plugintype_name('fulldeprecatedsubtype'));
|
||||
$this->assertEquals(
|
||||
'Fake full featured plugin / Full Sub Fakes',
|
||||
$pluginman->plugintype_name_plural('fulldeprecatedsubtype'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -980,8 +991,10 @@ final class plugin_manager_test extends \advanced_testcase {
|
||||
// Without string support, the type name defaults to the plugin type,
|
||||
// while plugin name is set in \core\plugininfo\base::init_is_deprecated().
|
||||
$this->assertEquals('fullfeatured', $pluginman->plugin_name('fake_fullfeatured'));
|
||||
$this->assertEquals('fake', $pluginman->plugintype_name('fake'));
|
||||
$this->assertEquals('fake', $pluginman->plugintype_name_plural('fake'));
|
||||
$this->assertEquals('[[type_fake]]', $pluginman->plugintype_name('fake'));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals('[[type_fake_plural]]', $pluginman->plugintype_name_plural('fake'));
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1056,7 +1069,15 @@ final class plugin_manager_test extends \advanced_testcase {
|
||||
// Without string support, the type name defaults to the plugin type,
|
||||
// while plugin name is set in \core\plugininfo\base::init_is_deprecated().
|
||||
$this->assertEquals('demo', $pluginman->plugin_name('fulldeletedsubtype_demo'));
|
||||
$this->assertEquals('fulldeletedsubtype', $pluginman->plugintype_name('fulldeletedsubtype'));
|
||||
$this->assertEquals('fulldeletedsubtype', $pluginman->plugintype_name_plural('fulldeletedsubtype'));
|
||||
$this->assertEquals(
|
||||
'Fake full featured plugin / [[subplugintype_fulldeletedsubtype]]',
|
||||
$pluginman->plugintype_name('fulldeletedsubtype'),
|
||||
);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals(
|
||||
'Fake full featured plugin / [[subplugintype_fulldeletedsubtype_plural]]',
|
||||
$pluginman->plugintype_name_plural('fulldeletedsubtype'),
|
||||
);
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user