diff --git a/engine/classes/Elgg/Groups/Tool.php b/engine/classes/Elgg/Groups/Tool.php index 5c0b183a8c3..394cc7f3ea9 100644 --- a/engine/classes/Elgg/Groups/Tool.php +++ b/engine/classes/Elgg/Groups/Tool.php @@ -79,7 +79,8 @@ public function getPriority() { } /** - * Get module title + * Get tool label + * * @return string */ public function getLabel() { @@ -91,6 +92,20 @@ public function getLabel() { return elgg_echo("groups:tool:{$this->name}"); } + /** + * Get tool description + * + * @return string|null + */ + public function getDescription(): ?string { + $lan_key = "groups:tool:{$this->name}:description"; + if (!elgg_language_key_exists($lan_key)) { + return null; + } + + return elgg_echo($lan_key); + } + /** * Is the tool enabled by default? * @return bool diff --git a/engine/tests/phpunit/unit/Elgg/Groups/ToolsUnitTest.php b/engine/tests/phpunit/unit/Elgg/Groups/ToolsUnitTest.php index db098807641..f1c90f19c34 100644 --- a/engine/tests/phpunit/unit/Elgg/Groups/ToolsUnitTest.php +++ b/engine/tests/phpunit/unit/Elgg/Groups/ToolsUnitTest.php @@ -36,7 +36,11 @@ public function testCanRegisterTools() { $this->assertEquals('yes', $tool->mapMetadataValue(true)); $this->assertEquals('no', $tool->mapMetadataValue(false)); $this->assertEquals(300, $tool->priority); - + + $this->assertNull($tool->getDescription()); + elgg()->translator->addTranslation('en', ['groups:tool:my-tool:description' => 'translated tool description']); + $this->assertEquals('translated tool description', $tool->getDescription()); + elgg()->group_tools->unregister('my-tool'); $tool = elgg()->group_tools->get('my-tool'); diff --git a/mod/groups/views/default/groups/edit/tool.php b/mod/groups/views/default/groups/edit/tool.php new file mode 100644 index 00000000000..ab7eda749f8 --- /dev/null +++ b/mod/groups/views/default/groups/edit/tool.php @@ -0,0 +1,26 @@ + 'checkbox', + '#label' => $tool->getLabel(), + '#help' => $tool->getDescription(), + '#class' => elgg_extract_class($vars), + 'name' => $tool->mapMetadataName(), + 'value' => 'yes', + 'default' => 'no', + 'switch' => true, + 'checked' => elgg_extract('value', $vars) === 'yes', +]); diff --git a/mod/groups/views/default/groups/edit/tools.php b/mod/groups/views/default/groups/edit/tools.php index 2054198031a..bbb60b0d5d8 100644 --- a/mod/groups/views/default/groups/edit/tools.php +++ b/mod/groups/views/default/groups/edit/tools.php @@ -7,30 +7,25 @@ $entity = elgg_extract('entity', $vars); -if ($entity instanceof ElggGroup) { +if ($entity instanceof \ElggGroup) { $tools = elgg()->group_tools->group($entity); } else { $tools = elgg()->group_tools->all(); } -$tools = $tools->sort()->all(); /* @var $tools \Elgg\Groups\Tool[] */ +$tools = $tools->sort(function (\Elgg\Groups\Tool $a, \Elgg\Groups\Tool$b) { + return strcmp($a->getLabel(), $b->getLabel()); +})->all(); if (empty($tools)) { return; } foreach ($tools as $tool) { - $prop_name = $tool->mapMetadataName(); - $value = elgg_extract($prop_name, $vars); - - echo elgg_view_field([ - '#type' => 'checkbox', - '#label' => $tool->label, - 'name' => $prop_name, - 'value' => 'yes', - 'default' => 'no', - 'switch' => true, - 'checked' => ($value === 'yes') ? true : false, + echo elgg_view('groups/edit/tool', [ + 'entity' => $entity, + 'tool' => $tool, + 'value' => elgg_extract($tool->mapMetadataName(), $vars), ]); }