Hi

I'm trying to add an image of a key to a view using the custom filter if the node has a password.

I've been trying for ages now with Custom filter then rewrite the results but with no luck :(

I believe there is no support in the filter or any of the views filters to enable this option?

Can I please request a views filter that will allow an image to be used?

Any help would be great!

Many thanks

CommentFileSizeAuthor
#5 Untitled.png27.94 KBBabymaggie

Comments

Babymaggie created an issue. See original summary.

izus’s picture

if you're looking for a condition to know if a node is protected in views, then the protected_node_views submodule offers it i think (it's called Node is protected)
try to enable that submodule and then you'll have the condition.

Babymaggie’s picture

Hi izus

Thanks for your reply.

The submodule is installed and the logic of the view seems to work fine.

The problem I'm getting is trying to get views to output an icon of a key instead of text, in my case {Locked}.

I would really like to be able to use the custom option of the output format to be able to accept an image? if that makes sense - unless there's an easier way?.

I expect it's me getting it wrong but no matter how I try to use views to rewrite the field with an image it just doesn't work :(

Any ideas?

Best wishes

grimreaper’s picture

Hello,

@Babymaggie: I don't understand the meaning of "an icon of a key"? For you what is the key? The password? the hashed password? The tip?

Babymaggie’s picture

StatusFileSize
new27.94 KB

Hi guys

I have attached an image of what I would like to try to create.

The left image is how the view looks now, the right image is how I would like my view to look with an image/icon of a key.

Any help is greatly appreciated :)

drupalove’s picture

I understand Protected Node is working properly and you just want to replace the text with a background image, you can achieve this with CSS.

Inspect the field which outputs the text {locked} to see if there is a class we can target.

Assuming there is a class called 'locked', use the snippet below in your stylesheet and replace the dimensions of the icon.

.locked {
  background: url(images/locked_icon.png) no-repeat 0 0;
  display: block;
  height: 18px;
  width: 20px;
  text-indent: -9999px;
}

If you inspected the field and found out there is no class, in the style settings of the field tick the checkbox 'Customize field HTML' and also tick the checkbox 'Create a CSS class'. In the field named 'CSS class' add a class called locked (without the dot).

It looks like the whole block is already centred; if the icon is not centred, add these two lines to the snippet:

margin-left: auto;
margin-right: auto;

If the icon is still not centred, try instead this:

text-align: center;

If the view is not made up of fields and there is no CSS class, the approach to adding a class will be different.

If that doesn't work for you, provide a URL to the page. If it works please update this issue.

Babymaggie’s picture

Hi drupalove

Many thanks for the above help, it has proved to be very useful!

The above advice works, I had to add as suggested:

margin-left: auto;
margin-right: auto;

and now it's almost what I want however the key icon is showing regardless of whether the node is locked or not.

Any ideas as to how to just display the key icon when the node is protected?

Many thanks for all the great advice so far.

drupalove’s picture

Grimreaper and Izus will be able to confirm if the module supports fields in views and they may help you while I'm away on holiday and don't have pc access yet.

Babymaggie’s picture

Thanks for all your help drupalove, have a great holiday!

Cheers

izus’s picture

Category: Feature request » Support request
grimreaper’s picture

Hello,

Yes using the protected_node_views sub-module, it adds views fields. One is "Protected node list: Node is protected". So you can have the output for your key image with this field.

In case it will not be enough flexible, try views conditional (https://www.drupal.org/project/views_conditional).

grimreaper’s picture

Version: 7.x-1.0-rc2 » 7.x-1.0

Hello,

@Babymaggie: Did this solution work for you? Can we close the issue?

Babymaggie’s picture

Hi Grimreaper

It helped lots thanks - I had to create an extra view that uses filter criteria: Protected node list: Node is protected (Yes) and use drupalove's reply #6

It's not ideal because of having to create the extra view but it works!

Many thanks to you all

grimreaper’s picture

Status: Active » Fixed

Hello,

Ok thanks. I mark the issue as fixed. Feel free to reopen in case of problem.

Thanks to all.

Status: Fixed » Closed (fixed)

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