I am printing a node in a mini panel. The node has a field for image, external link (link module) and node reference field. I want to link the image to the external link field.

What would be nice here is to have a new option for the pane that says link to: node/node reference field/external link etc or use an available substitution for linking.

Any ideas how to solve this?

Comments

itangalo’s picture

I would use Views for doing this – bringing in both fields and then doing a rewrite.

I guess this could be a part of generalized formatter in Panels (or even for the image field), but I don't see how it can be made generic enough without getting something similar to Views rewrites and stuff. So I would go for Views.

pontus_nilsson’s picture

Yes Views would be a solution but it feel wrong to have to boot up Views, load the entity all over again when it's already available in the mini panel. What if Views rewrite functions were available in ctools?

itangalo’s picture

Second best suggestion is to write a custom formatter for the image field, and somehow make it aware of token replacement patterns, or just any link fields on the same node.

itangalo’s picture

Oh, HERE's another solution.

Write a CTools relation plugin, that takes a string (including token replacement patterns) and returns a new string. That would basically do Views rewrites, without the need of the full Views framework.

Letharion’s picture

@Itanglo
What about moving the Views re-write functionality down the stack, making it available to Panels as well?

itangalo’s picture

#5: I don't know enough about the re-write functionality to say how possible this is, but in general I am all for it. Making components of a module accessible to other modules is goood.

Letharion’s picture

@merlin How feasible would it be to expose the "re-write this field"-functionality to content panes in Panels?
Adding a content "before" another, hiding it as we exclude in Views, and then getting a token in a "later" content pane? Would it have performance consequences?

One thing I don't really like, and that I feel could speak in favor of the solution in #1, is that keeping this functionality within Views keeps a nice separating between what content we generate and were we place it.
Other comments on that?

pontus_nilsson’s picture

To me it feels really wrong having to boot up Views in this matter. I mean everything is in place that we need and the entity is loaded. Having to load it in again in Views seems like a performance killer.

Letharion’s picture

Assigned: Unassigned » merlinofchaos

Yes, and I suppose I agree. It probably wouldn't be very good for performance at all once you do it in a few places. On the other hand, the panel could render cache the entire View.

Mostly, I completely agree with you, it's just the part about duplicating Views functionlity I don't like. :)

@merlin, Please see my question in #7 :)

merlinofchaos’s picture

In Panels, instead of using rewriting, you use context + content types.

Data is loaded in context, output is in content types. If you need to do custom manipulation, then that should be done in the context itself, where possible. With entities and formatters I think a LOT of the things you might ordinarily do with rewriting can be accomplished this way.

You can also use custom field panes and tokens from contexts to do a lot of custom text with the tokens, especially now that field tokens are working via token.module. This is something that probably could use a little tutorial, in fact.

itangalo’s picture

/me takes notes about the "tutorial" thing. It is now on my (pretty long) list.

pontus_nilsson’s picture

Hmmm... I need to try this out. Right now I don't see how I could show an image field with a specific image style and link it to an external link (link field).

merlinofchaos’s picture

#12: The issue there is that there may need to be a formatter that does what you want. Right now the entity pane can do the first part of that (image field with specific image style) but I don't believe the formatters currently allow linking to arbitrary paths.

merlinofchaos’s picture

Also, potentially a "custom" pane (in the UI) with token support enabled with something like this could do the trick:

<a href="%node:field-link">%node:field-image</a>
Letharion’s picture

Assigned: merlinofchaos » Unassigned

How about a formatter, that allows attaching to a text field and/or link field, which takes a "field-argument".

The formatter would then get the render of the "argument", and output l($argument, $link-field, HTML => true);

I'm not entirely sure how this would work myself, so I guess I'll just have to try. :)

pontus_nilsson’s picture

#13 Yes as you mention the ability to link to arbitary link field is missing from the formatter.

Could that be a setting that ctools can add? I mean an addition to the fields own formatter setting. I guess a new option in ctools_entity_field_content_type_formatter_options() or ctools_fields_get_field_formatter_settings_form() could add a list of all fields available in the context? I don't know enough about field formatters to know how we pass that on to rendering of the field properly.

Another idea, which also is a workaround is applying a style to the pane where the style wrapped the pane in a link. User interface wise it doesn't really makes sense to add it here though. I've made a sandbox project that demonstrates this .

Letharion’s picture

Status: Active » Closed (won't fix)

http://drupal.org/project/semantic_panels has been built partially to fix this. Won't be fixed in Panels.

Letharion’s picture

Issue summary: View changes

Better description.