From 62ee107166ba27fa30bdf9eb0e8fa0d6ad52de4f Mon Sep 17 00:00:00 2001
From: DvogelHallowelt <32163064+DvogelHallowelt@users.noreply.github.com>
Date: Wed, 16 Oct 2024 14:08:21 +0200
Subject: [PATCH] Improve LinkListGroupFromArray (#49)
* Improve LinkListGroupFromArray
* CC
* New interface
* CC
* Update ILinklistGroupFromArray.php
---------
Co-authored-by: Robert Vogel <1201528+osnard@users.noreply.github.com>
---
.../linklist-group-from-array.mustache | 6 ++---
.../SimpleLinklistGroupFromArray.php | 21 ++++++++++++++++--
src/IListRoleProvider.php | 16 ++++++++++++++
src/Renderer/LinklistGroupFromArray.php | 22 +++++++++++++++++++
4 files changed, 60 insertions(+), 5 deletions(-)
create mode 100644 src/IListRoleProvider.php
diff --git a/resources/templates/linklist-group-from-array.mustache b/resources/templates/linklist-group-from-array.mustache
index 0baa660..416a55c 100644
--- a/resources/templates/linklist-group-from-array.mustache
+++ b/resources/templates/linklist-group-from-array.mustache
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
diff --git a/src/Component/SimpleLinklistGroupFromArray.php b/src/Component/SimpleLinklistGroupFromArray.php
index 918915e..789ea8e 100644
--- a/src/Component/SimpleLinklistGroupFromArray.php
+++ b/src/Component/SimpleLinklistGroupFromArray.php
@@ -3,8 +3,9 @@
namespace MWStake\MediaWiki\Component\CommonUserInterface\Component;
use MWStake\MediaWiki\Component\CommonUserInterface\ILinklistGroupFromArray;
+use MWStake\MediaWiki\Component\CommonUserInterface\IListRoleProvider;
-class SimpleLinklistGroupFromArray extends ComponentBase implements ILinklistGroupFromArray {
+class SimpleLinklistGroupFromArray extends ComponentBase implements ILinklistGroupFromArray, IListRoleProvider {
/**
* @param array $options
@@ -15,7 +16,9 @@ public function __construct( $options ) {
'id' => '',
'links' => [],
'classes' => [],
- 'aria' => []
+ 'aria' => [],
+ 'role' => '',
+ 'item-role' => ''
],
$options
);
@@ -48,4 +51,18 @@ public function getContainerClasses(): array {
public function getAriaAttributes(): array {
return $this->options['aria'];
}
+
+ /**
+ * @inheritDoc
+ */
+ public function getContainerRole(): string {
+ return $this->options['role'];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getItemRole(): string {
+ return $this->options['item-role'];
+ }
}
diff --git a/src/IListRoleProvider.php b/src/IListRoleProvider.php
new file mode 100644
index 0000000..4807ac0
--- /dev/null
+++ b/src/IListRoleProvider.php
@@ -0,0 +1,16 @@
+getContainerRole();
+ if ( $role !== '' ) {
+ $templateData = array_merge(
+ $templateData,
+ [
+ 'cnt-role' => $role
+ ]
+ );
+ }
+ $itemRole = $component->getItemRole();
+ if ( $itemRole !== '' ) {
+ $templateData = array_merge(
+ $templateData,
+ [
+ 'item-role' => $itemRole
+ ]
+ );
+ }
+ }
} else {
throw new Exception( "Can not extract data from " . get_class( $component ) );
}