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.

Files: 
CommentFileSizeAuthor
#26 1306564-26.patch726 bytesdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 50,321 pass(es).
[ View ]
#22 views-1306564-22-d7.patch553 bytesdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 1,603 pass(es).
[ View ]
#22 views-1306564-22-d8-do-not-test.patch665 bytesdamiankloip
#18 1306564-18.patch4.59 KBdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 1,533 pass(es).
[ View ]
#17 1306564-17.patch3.25 KBdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 1,533 pass(es).
[ View ]
#16 1306564-16.patch3.25 KBdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 1,464 pass(es).
[ View ]
#9 1306564-9.patch3.16 KBdawehner
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]
#8 1306564-8.patch3.19 KBdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]
#6 1306564-views-hide-admin-links.patch4.66 KBdamiankloip
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]

Comments

Status:Active» Fixed

Just use this simple code snippet:

$view->hide_admin_links = TRUE;

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Thanks 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

Category:support» feature
Status:Closed (fixed)» Needs review

Changing 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.

Status:Needs review» Active

Update status

Version:7.x-3.0-beta3» 7.x-3.x-dev
Status:Active» Needs review
StatusFileSize
new4.66 KB
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]

I have found a couple of instances where this would have been handy. How about something like this?

As a note on the patch, hide_admin_links is set in the pre_execute() for the plugin. Is that the best place for that?

StatusFileSize
new3.19 KB
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]

Here 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.

StatusFileSize
new3.16 KB
PASSED: [[SimpleTest]]: [MySQL] 1,458 pass(es).
[ View ]

Just a small skitch what i had in mind.

Status:Needs review» Needs work

+++ b/plugins/views_plugin_display.incundefined
@@ -532,6 +534,10 @@ class views_plugin_display extends views_plugin {
+      'hide_admin_links' => array(
+        'default' => empty($this->definition['contextual links locations']),
+        'bool' => TRUE,

Ah, so mainly just change this part to be dynamic?

Status:Needs work» Needs review

oops

Hmm, 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).

Ah i see what you mean ...

    // If contextual links locations are not set, provide a sane default. (To
    // avoid displaying any contextual links at all, a display plugin can still
    // set 'contextual links locations' to, e.g., an empty array.)
    $plugin += array('contextual links locations' => array('view'));

Yes, that will do it :) What do you think then?

Having 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() ?

StatusFileSize
new3.25 KB
PASSED: [[SimpleTest]]: [MySQL] 1,464 pass(es).
[ View ]

dawehner, 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.

StatusFileSize
new3.25 KB
PASSED: [[SimpleTest]]: [MySQL] 1,533 pass(es).
[ View ]

logic changed for the visibility of this option:

!isset($this->definition['contextual links locations']) || !empty($this->definition['contextual links locations'])

StatusFileSize
new4.59 KB
PASSED: [[SimpleTest]]: [MySQL] 1,533 pass(es).
[ View ]

With updated docs in views.api.php

Status:Needs review» Fixed

Awseome! Committed to 8.x-3.x and 7.x-3.x, though it didn't applied to the plugins branch, what a wonder ...

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Could someone explain why it is that 'hide_admin_links' => FALSE in views_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.

Status:Closed (fixed)» Needs review
StatusFileSize
new665 bytes
new553 bytes
PASSED: [[SimpleTest]]: [MySQL] 1,603 pass(es).
[ View ]

@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.

Status:Needs review» Reviewed & tested by the community

With damiankloip in agreement, I guess it's okay for me to mark this RTBC.

I've confirmed the fix using the D7 patch.

#22: views-1306564-22-d7.patch queued for re-testing.

+1

Project:Views» Drupal core
Version:7.x-3.x-dev» 8.x-dev
Component:User interface» views.module
Status:Reviewed & tested by the community» Needs review
StatusFileSize
new726 bytes
PASSED: [[SimpleTest]]: [MySQL] 50,321 pass(es).
[ View ]

Committed 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.

Thank you guys! I needed it, found this thread and it made my day :)

Status:Needs review» Fixed

I guess this is not needed for d8 anymore.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.