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

Empty accesskeys in navigation #5586

Closed
CMSworker opened this issue Dec 16, 2022 · 5 comments · Fixed by #5590
Closed

Empty accesskeys in navigation #5586

CMSworker opened this issue Dec 16, 2022 · 5 comments · Fixed by #5590
Labels
Milestone

Comments

@CMSworker
Copy link
Contributor

CMSworker commented Dec 16, 2022

Affected version(s)

5.0.7

Description

In a local test installation of Contao 5.0.7 in XAMPP (PHP 8.1.6) I noticed multiple empty accesskey="" in the HTML source code of navigation blocks. I did not set any keyboard shortcuts in the page settings in the backend. The accesskey fields in the backend show 0 as default value.

To investigate it, I made a copy of the template nav_default.html5 and added a variable dump with

echo \Contao\Template::dumpTemplateVars();

In the array lists accesskey => false is defined for all navigation elements.

The accesskey is generated in this line in the template file:

<li<?php if ($item['class']): ?> class="<?= $item['class'] ?>"<?php endif; ?>><a href="<?= $item['href'] ?>" title="<?= $item['pageTitle'] ?: $item['title'] ?>"<?php if ($item['class']): ?> class="<?= $item['class'] ?>"<?php endif; ?><?php if ('' !== $item['accesskey']): ?> accesskey="<?= $item['accesskey'] ?>"<?php endif; ?><?= $item['target'] ?><?= $item['rel'] ?? '' ?><?php if (!empty($item['subitems'])): ?> aria-haspopup="true"<?php endif; ?>><?= $item['link'] ?></a><?= $item['subitems'] ?? '' ?></li>

To avoid the generation of the empty accesskeys I modified this snippet:
<?php if ('' !== $item['accesskey'] ): ?>
to this:
<?php if ('' !== $item['accesskey'] && $item['accesskey'] != false ): ?>

If someone can confirm the generation of empty accesskeys, it could be fixed in the core template.

@leofeyer leofeyer added this to the 5.0 milestone Dec 16, 2022
@leofeyer
Copy link
Member

It should probably be <?php if (!$item['accesskey']): ?> or <?php if (!empty($item['accesskey'])): ?>.

@CMSworker
Copy link
Contributor Author

<?php if (!$item['accesskey']): ?> doesn't work.

<?php if (!empty($item['accesskey'])): ?> works. Thank you.

@CMSworker
Copy link
Contributor Author

@ausi noted that the change "would break accesskey="0""
and suggested <?php if ('' !== (string) $item['accesskey']): ?>

I tested ausi's variant, it would work.

BUT I noticed that you can't declare accesskey 0 in Contao 5.0.7, at least in my test installation.

In the online demo (Contao 4.13.14) the input field for page accesskeys looks like this:

accesskey-alt

In my local Contao 5.0.7 installation it looks like this by default:

accesskey

I did not enter the zero number. 0 is the default value. When you save the page with accesskey 0, it will not be rendered in the frontend's HTML code, no matter how I change the nav_default.html5 template.

I also noticed you can only enter numbers in this field. When you enter any letter and save the page, it gets converted to a number. Is this behaviour correct/intended for accesskeys?

@fritzmg
Copy link
Contributor

fritzmg commented Dec 18, 2022

This is actually an accidental change from #4797. I'll provide a PR to fix it.

@fritzmg
Copy link
Contributor

fritzmg commented Dec 18, 2022

See #5590

@fritzmg fritzmg closed this as completed Dec 18, 2022
@fritzmg fritzmg linked a pull request Dec 18, 2022 that will close this issue
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants