Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hello, I am trying to render some view programmatically, by invoking:
$rendered = $view->execute_display($displayName);
View renders as usual, with all the context links depending on currently logged in user. But I need this $rendered HTML to be without any contextual links (without both view and node contextual links) even when logged in as administrator.
So, how do I tell views not to render contextual links at all?
Or, is it possible to render the view as for anonymous user (in this case contextual links will go away as well)?
Thank you.
Comment | File | Size | Author |
---|---|---|---|
#26 | 1306564-26.patch | 726 bytes | damiankloip |
#22 | views-1306564-22-d7.patch | 553 bytes | damiankloip |
#22 | views-1306564-22-d8-do-not-test.patch | 665 bytes | damiankloip |
#18 | 1306564-18.patch | 4.59 KB | damiankloip |
#17 | 1306564-17.patch | 3.25 KB | damiankloip |
Comments
Comment #1
dawehnerJust use this simple code snippet:
Comment #3
davidwhthomas CreditAttribution: davidwhthomas commentedThanks for this tip!
Is there also a way to hide contextual links from within the Views admin UI?
I'm finding the contextual links are being output in a empty view, resulting in cruft content titles in the template.
I had a look, but couldn't see a
$view->hide_admin_links = TRUE;
type setting in the Views UI.
Dt
Comment #4
alexverb CreditAttribution: alexverb commentedChanging this to a feature request:
I also vote for an option in the UI. I'm embedding a view with the viewfield module to send out as a newsletter. I have no access to any code and also wish to hide those admin links.
Comment #5
dawehnerUpdate status
Comment #6
damiankloip CreditAttribution: damiankloip commentedI have found a couple of instances where this would have been handy. How about something like this?
Comment #7
damiankloip CreditAttribution: damiankloip commentedAs a note on the patch, hide_admin_links is set in the pre_execute() for the plugin. Is that the best place for that?
Comment #8
damiankloip CreditAttribution: damiankloip commentedHere is an updated patch that relies on whether contextual links locations have been declared instead of directly adding a 'hide admin links' element to the plugin definition.
Comment #9
dawehnerJust a small skitch what i had in mind.
Comment #10
damiankloip CreditAttribution: damiankloip commentedAh, so mainly just change this part to be dynamic?
Comment #11
damiankloip CreditAttribution: damiankloip commentedoops
Comment #12
damiankloip CreditAttribution: damiankloip commentedHmm, I'm not sure now. for example, in admin views, they would now all default to contextual links off beause the plugin definition doesn't declare a 'contextual link locations'. Is this what we want? or should admin views be declaring this? (It isn't needed to have contextual links).
Comment #13
dawehnerAh i see what you mean ...
Comment #14
damiankloip CreditAttribution: damiankloip commentedYes, that will do it :) What do you think then?
Comment #15
dawehnerHaving the need for two different kind of flags is kind of odd, because from my perspective having one would somehow be enough.
Can't be check whether it's != array() ?
Comment #16
damiankloip CreditAttribution: damiankloip commenteddawehner, here is a new patch as discussed on IRC. Yes, I think we should check that 'contextual links locations' isset() and is_array(). This would then work how I expect it to; so page, block, attachment will show this option, and feed etc... will not. I also think the default value for this should always be 'No'. Let me know what you think.
Comment #17
damiankloip CreditAttribution: damiankloip commentedlogic changed for the visibility of this option:
!isset($this->definition['contextual links locations']) || !empty($this->definition['contextual links locations'])
Comment #18
damiankloip CreditAttribution: damiankloip commentedWith updated docs in views.api.php
Comment #19
dawehnerAwseome! Committed to 8.x-3.x and 7.x-3.x, though it didn't applied to the plugins branch, what a wonder ...
Comment #21
jweowu CreditAttribution: jweowu commentedCould someone explain why it is that
'hide_admin_links' => FALSE
inviews_plugin_display::option_definition()
?That makes this option over-ridden by default when creating a new display, but the default value for the Master display is 'No', and the default for the over-ridden values is likewise 'No', so I don't understand why this isn't
TRUE
like most other options that are only over-ridden on demand?Thanks.
Comment #22
damiankloip CreditAttribution: damiankloip commented@jweowu This totally makes sense. I have just tested this out to makes sure it makes sense, and I think it does. Here are patches for both 7.x and 8.x branches.
Comment #23
jweowu CreditAttribution: jweowu commentedWith damiankloip in agreement, I guess it's okay for me to mark this RTBC.
I've confirmed the fix using the D7 patch.
Comment #24
damiankloip CreditAttribution: damiankloip commented#22: views-1306564-22-d7.patch queued for re-testing.
Comment #25
dawehner+1
Comment #26
damiankloip CreditAttribution: damiankloip commentedCommitted and pushed to 7.x-3.x. Now we can move this to 8.x/core.
Here is a re rolled 8.x patch now views is in core.
Comment #27
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedThank you guys! I needed it, found this thread and it made my day :)
Comment #28
dawehnerI guess this is not needed for d8 anymore.