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 commentedComment #3
dawehnerI'm curious whether this is a BC compatible change ...
Comment #5
Jmdrawneek@googlemail.com commentedNot too sure why this is failing. I've applied it locally and it seemed to apply fine.
Comment #6
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 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 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.urlIt'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 commentedOK I got it, will test later today.
Think that this has a semantic issue.
The
linkobject 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
linkobject 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 commentedThanks for the support.
While patch been applied to Core, use this workaround:
Then render the
itemvariableComment #19
joelpittetTotally, that is a good work around:)
Comment #20
joelpittetComment #36
smustgrave commentedThank you for sharing your idea for improving Drupal.
We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #37
smustgrave commentedSince there's been no follow up and a feature request going to close out. Can always be re-opened
Thanks all!