Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LinkListGroupFromArray #49

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions resources/templates/linklist-group-from-array.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul {{#cnt-id}} id="{{.}}" {{/cnt-id}}class="list-group{{#cnt-class}} {{.}}{{/cnt-class}}"{{#cnt-aria}} {{{.}}}{{/cnt-aria}} role="group">
<ul {{#cnt-id}} id="{{.}}" {{/cnt-id}}class="list-group{{#cnt-class}} {{.}}{{/cnt-class}}"{{#cnt-aria}} {{{.}}}{{/cnt-aria}}{{#cnt-role}} role="{{.}}"{{/cnt-role}}>
{{#links}}
<li class="list-group-item">
<a{{#id}} id="{{.}}"{{/id}}{{#class}} class="{{.}}"{{/class}} href="{{href}}"{{#title}} title="{{.}}"{{/title}}{{#data}} {{{.}}}{{/data}}{{#aria}} {{{.}}}{{/aria}}{{#rel}} rel="{{.}}"{{/rel}}{{#target}} target="{{.}}"{{/target}}>{{{text}}}</a>
<li class="list-group-item"{{#item-role}} role="{{.}}"{{/item-role}}>
<a{{#id}} id="{{.}}"{{/id}}{{#class}} class="{{.}}"{{/class}} href="{{href}}"{{#title}} title="{{.}}"{{/title}}{{#data}} {{{.}}}{{/data}}{{#aria}} {{{.}}}{{/aria}}{{#rel}} rel="{{.}}"{{/rel}}{{#target}} target="{{.}}"{{/target}}{{#role}} role="{{.}}"{{/role}}>{{{text}}}</a>
</li>
{{/links}}
</ul>
21 changes: 19 additions & 2 deletions src/Component/SimpleLinklistGroupFromArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +16,9 @@ public function __construct( $options ) {
'id' => '',
'links' => [],
'classes' => [],
'aria' => []
'aria' => [],
'role' => '',
'item-role' => ''
],
$options
);
Expand Down Expand Up @@ -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'];
}
}
16 changes: 16 additions & 0 deletions src/IListRoleProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace MWStake\MediaWiki\Component\CommonUserInterface;

interface IListRoleProvider {

/**
* @return string
*/
public function getContainerRole(): string;

/**
* @return string
*/
public function getItemRole(): string;
}
22 changes: 22 additions & 0 deletions src/Renderer/LinklistGroupFromArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MWStake\MediaWiki\Component\CommonUserInterface\DataAttributesBuilder;
use MWStake\MediaWiki\Component\CommonUserInterface\IComponent;
use MWStake\MediaWiki\Component\CommonUserInterface\ILinklistGroupFromArray;
use MWStake\MediaWiki\Component\CommonUserInterface\IListRoleProvider;

class LinklistGroupFromArray extends RendererBase {

Expand Down Expand Up @@ -72,6 +73,27 @@ public function getRendererDataTreeNode( $component, $subComponentNodes ): array
]
);
}

if ( $component instanceof IListRoleProvider ) {
$role = $component->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 ) );
}
Expand Down
Loading