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

Add an "ARIA label" field to the navigation module #7209

Open
wants to merge 3 commits into
base: 5.x
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions core-bundle/contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
(
'__selector__' => array('type', 'defineRoot', 'protected', 'reg_assignDir', 'reg_activate'),
'default' => '{title_legend},name,type',
'navigation' => '{title_legend},name,headline,type;{nav_legend},levelOffset,showLevel,hardLimit,showProtected,showHidden;{reference_legend:hide},defineRoot;{template_legend:hide},customTpl,navigationTpl;{protected_legend:hide},protected;{expert_legend:hide},cssID',
'navigation' => '{title_legend},name,headline,type;{label_legend},ariaLabel;{nav_legend},showProtected,showHidden,levelOffset,showLevel,hardLimit;{reference_legend:hide},defineRoot;{template_legend:hide},customTpl,navigationTpl;{protected_legend:hide},protected;{expert_legend:hide},cssID',
'customnav' => '{title_legend},name,headline,type;{nav_legend},pages,showProtected;{template_legend:hide},customTpl,navigationTpl;{protected_legend:hide},protected;{expert_legend:hide},cssID',
'breadcrumb' => '{title_legend},name,headline,type;{nav_legend},showHidden;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},cssID',
'quicknav' => '{title_legend},name,headline,type;{label_legend},customLabel;{nav_legend},showLevel,hardLimit,showProtected,showHidden;{reference_legend:hide},rootPage;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},cssID',
Expand Down Expand Up @@ -147,22 +147,28 @@
'eval' => array('helpwizard'=>true, 'chosen'=>true, 'submitOnChange'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(64) COLLATE ascii_bin NOT NULL default 'navigation'"
),
'ariaLabel' => array
(
'inputType' => 'text',
'eval' => array('maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'levelOffset' => array
(
'inputType' => 'text',
'eval' => array('maxlength'=>5, 'rgxp'=>'natural', 'tl_class'=>'w50'),
'eval' => array('maxlength'=>5, 'rgxp'=>'natural', 'tl_class'=>'w25 clr'),
'sql' => "smallint(5) unsigned NOT NULL default 0"
),
'showLevel' => array
(
'inputType' => 'text',
'eval' => array('maxlength'=>5, 'rgxp'=>'natural', 'tl_class'=>'w50'),
'eval' => array('maxlength'=>5, 'rgxp'=>'natural', 'tl_class'=>'w25'),
'sql' => "smallint(5) unsigned NOT NULL default 0"
),
'hardLimit' => array
(
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w25 clr'),
'eval' => array('tl_class'=>'w25 m12'),
'sql' => array('type' => 'boolean', 'default' => false),
),
'showProtected' => array
Expand Down
8 changes: 4 additions & 4 deletions core-bundle/contao/languages/en/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1965,16 +1965,16 @@
<source>You have to add a website root page to enter file metadata.</source>
</trans-unit>
<trans-unit id="MSC.breadcrumbMenu">
<source>Breadcrumb menu</source>
<source>Breadcrumb</source>
</trans-unit>
<trans-unit id="MSC.mainNavigation">
<source>Main navigation</source>
<source>Main</source>
</trans-unit>
<trans-unit id="MSC.headerNavigation">
<source>Header navigation</source>
<source>Header</source>
</trans-unit>
<trans-unit id="MSC.pagination">
<source>Pagination menu</source>
<source>Pagination</source>
</trans-unit>
<trans-unit id="MSC.validCharacters.unicodeLowercase">
<source>Unicode numbers and lowercase letters</source>
Expand Down
6 changes: 6 additions & 0 deletions core-bundle/contao/languages/en/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<trans-unit id="tl_module.type.1">
<source>Please choose the type of module.</source>
</trans-unit>
<trans-unit id="tl_module.ariaLabel.0">
<source>ARIA label</source>
</trans-unit>
<trans-unit id="tl_module.ariaLabel.1">
<source>Here you can enter an ARIA label. Avoid using the role in the label, as screen readers read out both the label and the role. For example, "Main navigation" would be read as "Main navigation navigation".</source>
</trans-unit>
<trans-unit id="tl_module.levelOffset.0">
<source>Start level</source>
</trans-unit>
Expand Down
2 changes: 2 additions & 0 deletions core-bundle/contao/library/Contao/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ public function generate($strSeparator=' ')
);

$objTemplate->class = 'pagination-' . $this->strParameter;

// Backwards compatibility
$objTemplate->pagination = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['pagination']);

// Adding rel="prev" and rel="next" links is not possible
Expand Down
4 changes: 4 additions & 0 deletions core-bundle/contao/models/ModuleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @property string $name
* @property string $headline
* @property string $type
* @property string $ariaLabel
* @property integer $levelOffset
* @property integer $showLevel
* @property boolean $hardLimit
Expand Down Expand Up @@ -92,6 +93,7 @@
* @method static ModuleModel|null findOneByName($val, array $opt=array())
* @method static ModuleModel|null findOneByHeadline($val, array $opt=array())
* @method static ModuleModel|null findOneByType($val, array $opt=array())
* @method static ModuleModel|null findOneByAriaLabel($val, array $opt=array())
* @method static ModuleModel|null findOneByLevelOffset($val, array $opt=array())
* @method static ModuleModel|null findOneByShowLevel($val, array $opt=array())
* @method static ModuleModel|null findOneByHardLimit($val, array $opt=array())
Expand Down Expand Up @@ -157,6 +159,7 @@
* @method static Collection<ModuleModel>|ModuleModel[]|null findByName($val, array $opt=array())
* @method static Collection<ModuleModel>|ModuleModel[]|null findByHeadline($val, array $opt=array())
* @method static Collection<ModuleModel>|ModuleModel[]|null findByType($val, array $opt=array())
* @method static Collection<ModuleModel>|ModuleModel[]|null findByAriaLabel($val, array $opt=array())
* @method static Collection<ModuleModel>|ModuleModel[]|null findByLevelOffset($val, array $opt=array())
* @method static Collection<ModuleModel>|ModuleModel[]|null findByShowLevel($val, array $opt=array())
* @method static Collection<ModuleModel>|ModuleModel[]|null findByHardLimit($val, array $opt=array())
Expand Down Expand Up @@ -226,6 +229,7 @@
* @method static integer countByName($val, array $opt=array())
* @method static integer countByHeadline($val, array $opt=array())
* @method static integer countByType($val, array $opt=array())
* @method static integer countByAriaLabel($val, array $opt=array())
* @method static integer countByLevelOffset($val, array $opt=array())
* @method static integer countByShowLevel($val, array $opt=array())
* @method static integer countByHardLimit($val, array $opt=array())
Expand Down
1 change: 1 addition & 0 deletions core-bundle/contao/modules/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @property string $name
* @property string $headline
* @property string $type
* @property string $ariaLabel
* @property integer $levelOffset
* @property integer $showLevel
* @property boolean $hardLimit
Expand Down
1 change: 1 addition & 0 deletions core-bundle/contao/modules/ModuleNavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected function compile()
$host = $objRootPage->domain;
}

$this->Template->ariaLabel = StringUtil::specialchars($this->ariaLabel);
$this->Template->request = StringUtil::ampersand(Environment::get('requestUri'));
$this->Template->skipId = 'skipNavigation' . $this->id;
$this->Template->skipNavigation = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['skipNavigation']);
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/contao/templates/backend/be_pagination.html5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<nav class="pagination <?= $this->class ?>" aria-label="<?= $this->pagination ?>">
<nav class="pagination <?= $this->class ?>" aria-label="<?= $this->trans('MSC.pagination') ?>">

<p><?= $this->total ?></p>

Expand Down
2 changes: 1 addition & 1 deletion core-bundle/contao/templates/modules/mod_breadcrumb.html5
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $this->wrapperAttributes = $this
->attr($this->cssID)
->addClass([$this->class, 'block'])
->addStyle($this->style)
->set('aria-label', 'Breadcrumb')
->set('aria-label', $this->trans('MSC.breadcrumbMenu'))
->mergeWith($this->wrapperAttributes)
;

Expand Down
1 change: 1 addition & 0 deletions core-bundle/contao/templates/modules/mod_navigation.html5
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $this->wrapperAttributes = $this
->attr($this->cssID)
->addClass([$this->class, 'block'])
->addStyle($this->style)
->setIfExists('aria-label', $this->ariaLabel)
fritzmg marked this conversation as resolved.
Show resolved Hide resolved
->mergeWith($this->wrapperAttributes)
;

Expand Down
2 changes: 1 addition & 1 deletion core-bundle/contao/templates/pagination/pagination.html5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<!-- indexer::stop -->
<nav class="pagination block" aria-label="<?= $this->pagination ?>">
<nav class="pagination block" aria-label="<?= $this->trans('MSC.pagination') ?>">

<p><?= $this->total ?></p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment as TwigEnvironment;
use Twig\Loader\LoaderInterface;

Expand Down Expand Up @@ -363,6 +364,7 @@ private function mockContainer(RequestStack|null $requestStack = null, callable|
$this->container->set('contao.framework', $framework);
$this->container->set('contao.routing.scope_matcher', $this->mockScopeMatcher());
$this->container->set('cache.system', $this->createMock(CacheInterface::class));
$this->container->set('translator', $this->createMock(TranslatorInterface::class));

if ($requestStack instanceof RequestStack) {
$this->container->set('request_stack', $requestStack);
Expand Down