Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am trying to add custom class to the link ('a' tag) on menu local task with no success.
This is the code used:
<?php
{#
/**
* @file
* Bootstrap Barrio's Theme override for a local task link.
*
* Available variables:
* - attributes: HTML attributes for the wrapper element.
* - is_active: Whether the task item is an active tab.
* - link: A rendered link element.
*
* Note: This template renders the content for each task item in
* menu-local-tasks.html.twig.
*
* @see template_preprocess_menu_local_task()
*/
#}
<li{{ attributes.addClass(is_active ? 'active', 'nav-item') }}>{{ link(item.title, item.url, {'class' : 'nav-link' }) }}</li>
?>
Throwing this error:
[Fri Nov 13 02:22:39.011213 2015] [:error] [pid 2800:tid 1140] [client ::1:52515] Uncaught PHP Exception InvalidArgumentException: "The URI '' is invalid. You must use a valid URI scheme." at C:\\Bitnami\\drupal-8.0.0.rc2-0\\apps\\drupal\\htdocs\\core\\lib\\Drupal\\Core\\Url.php line 301, referer: http://localhost/drupal/node/2
Comment | File | Size | Author |
---|---|---|---|
#14 | interdiff.txt | 768 bytes | dawehner |
#14 | 2614628-14.patch | 2.01 KB | dawehner |
#3 | 2614628-3.patch | 1.41 KB | dawehner |
Comments
Comment #2
hatuhay CreditAttribution: hatuhay commentedComment #3
dawehnerI'm curious whether this is a BC compatible change ...
Comment #5
Jmdrawneek@googlemail.com CreditAttribution: Jmdrawneek@googlemail.com at Curve Agency commentedNot too sure why this is failing. I've applied it locally and it seemed to apply fine.
Comment #6
hatuhay CreditAttribution: hatuhay commentedApply the patch.
This works OK.
This one throws same error
"The URI '' is invalid. You must use a valid URI scheme."
Comment #7
joelpittetSeems to have passed. Moving to 8.0. and tagging.
This issue looks handy:)
Comment #8
hatuhay CreditAttribution: hatuhay commentedYes, and it is also needed for menu local actions.
But please, the patch still throw errors.
Comment #9
joelpittetWhat errors does the patch throw? It looks like a Proof of Concept but it doesn't look to throw errors.
Setting to needs work to tackle both local tasks and local actions.
Comment #10
hatuhay CreditAttribution: hatuhay commentedThis code applied on
template_preprocess_menu_local_task()
Throw this error:
"The URI '' is invalid. You must use a valid URI scheme."
Comment #11
joelpittet@hatuhay The error has nothing to do with the class it's to do with
item.url
It's saying that empty string '' is not a valid URL.Meaning that item.url doesn't exist. @dawehner has been a bit clever and used the Link object which has access to some of those properties which I believe is a brilliant approach.
Comment #12
joelpittetWhoops was middle of clarifying the title a bit.
Comment #13
hatuhay CreditAttribution: hatuhay commentedOK I got it, will test later today.
Think that this has a semantic issue.
The
link
object confuse me with thelink()
function.To many info in short time.
This is tough to do, so do not expect to be done but my believe is that
link
object should be renamed toitem
.Comment #14
dawehner@hatuhay
You used the template in the wrong way:
though works.
This patch here also expands to local actions
Comment #16
joelpittet@dawehner Unfortunately the Link object doesn't allow setting Attributes or any other link #options. That may need to be a follow-up (if it doesn't exist) maybe for now we can just provide the template with some extra context variables?
Your approach seems ideal but maybe a bit of a stretch unless we can get the Link object a bit more useful.
Comment #17
joelpittetI may be crazy but here's making Link take attributes. A bit of a WIP and needs tests but may suffice.
#2615660: Allow Link and LinkGenerator::generate() to provide attributes.
Comment #18
hatuhay CreditAttribution: hatuhay commentedThanks for the support.
While patch been applied to Core, use this workaround:
Then render the
item
variableComment #19
joelpittetTotally, that is a good work around:)
Comment #20
joelpittet