There have been a few bugs reported with the "Content item" widget, with regard to the fact that the title field isn't a real reference to a particular node, for example:

#2108821: Problems selecting specific "Content item" when titles are the same or similar
#1971428: add a generic piece of content filter issue

To sum up the problems quickly: it's a title field that has autocomplete. So, if two nodes have the same title, you can't pick one or the other. Or, if the title you want is a subset of another title, it sometimes favors the other, rather than the exact match. Or, if you refer to title, and then later the title is changed, the reference is broken.

It would be great to use a real entity reference field of some kind, rather than a title field!

I haven't dug into this much yet - I'm not sure it's possible with raw Views. I found this project on Drupal.org:

https://www.drupal.org/project/entityreference_filter

But I haven't tested it. We could also probably write a quick Views plugin for our purposes!

Comments

caschbre’s picture

Just curious, but why do we we have the "Content item" pane? It seems like the out-of-the-box "Existing node" pane would be better to use. It has a direct reference to the node to display and you can choose which display mode to use. Using the View to display just one item seems odd.

We seem to by trying to hack around the View. Looking at the View you'd want to use a contextual filter instead of an exposed filter. Trying to use the exposed filter on the title is definitely going to lead to issues.

I'd actually argue that it would be better in the long run to change out the "Add content item" with the "Existing node" pane.

dsnopek’s picture

Just curious, but why do we we have the "Content item" pane? It seems like the out-of-the-box "Existing node" pane would be better to use.

I don't know the original motivation, but there are a few features the "Content item" widget has that "Existing node" does not:

  • Simplified UI: the "Existing node" has advanced fields like "Template identifier"
  • Live preview works flawlessly (not sure why it behaves strangely with "Existing node" - we should probably open an issue for that)
  • Ability to turn fields on and off in a simplistic way without having to create a new view mode
  • Ability to create a table (although, I'm not sure anyone actually does this)

In any case, at this point we're not going to remove the "Content item" widget, but we could change it's implementation in a backward-compatible way to fix problems.

caschbre’s picture

Yeah, I don't think we should remove the content item widget, but what if we made it a wrapper to the existing node pane?

  • Simplifying the UI should be pretty easy. We can hide some of those things like template identifier or wrap those in an advanced settings fieldset.
  • It would be nice to get the live preview working with existing node regardless.
  • Turning fields on/off should also be something we could do. Wouldn't that just be a preprocessor?
  • The table did make me grin. :) I found it interesting as a 'content item' widget. Took me a few minutes to realize it's just pulling from the content list widget where the table makes more sense.

I'm just wondering if we'll spend more time hacking around making the View work as existing node already does instead of just enhancing existing node (and making our current content item just wrap that).

dsnopek’s picture

Yeah, I don't think we should remove the content item widget, but what if we made it a wrapper to the existing node pane?

I'd really prefer not to do this. If we change the implementation of "Content item" to be something that isn't a View, we shouldn't be customizing the "Existing node" widget, but creating a totally new widget with a similar implementation.

Many Panopoly users are already using "Existing node" for advanced use cases, but giving general users access to "Content item". If we try to conflate those, then they'll lose their advanced widget, or we'll need to have a way to optionally remove our customizations, and lots of complication will ensue.

But that said, I think the Views-based implementation is fine, and I don't see any reason to switch away from that. Views can take NIDs too! It's just that the current implementation takes a title, rather than a reference. I'd prefer just to fix that bit.

It would be nice to get the live preview working with existing node regardless.

Agreed, but that's totally seperate. I just made a new issue for it: #2334877: Fix live preview with "Existing node" widget

caschbre’s picture

we shouldn't be customizing the "Existing node" widget

Yeah, I don't mean to suggest that we change the behavior of the "Existing node" widget. That should be left unaltered for it's own use. What I was thinking is we still have a "Content Item" widget that uses existing node as a baseline. The Content Item can add new functionality or hide existing node functionality without altering existing node. This would leave existing node for advanced uses and keep the content item as the more general case... but overall they'll end up fairly consistent.

If we continue with the Views approach, we'll want to add a contextual filter to the View that accepts the NID as opposed to throwing a new module (e.g. entityreference_filter) into the mix. If I remember correctly a contextual argument can be exposed to the panel pane configuration screen, though I'm not sure it's autocomplete out of the box for the nid lookup.

dsnopek’s picture

Assigned: Unassigned » dsnopek
Status: Active » Needs review
StatusFileSize
new3.85 KB

Attached is an initial proof-of-concept patch that does this!

I experimented with a bunch of possible approaches:

  1. Keeping Views, but dropping views_autocomplete_filter and doing our own autocomplete magic on an NID filter or argument
  2. Keeping Views and views_autocomplete_filter on the title field, but adding custom code to store/load to/from NID in the Pane configuration
  3. Creating a whole new custom CTools content type in custom code, without Views

I ended up going with #2, because it provided the fewest changes to existing functionality. views_autocomplete_filter actually gets us the cool "filter autocomplete by content type" functionality, and Views lets us easily continue to use this for both a "Facebook media item" (ie. image next to title, like you get with "Fields" display type) and node view modes.

These things still need to be done before committing, though:

  • Behat tests!
  • Use the View itself to look up the NID, rather than node_load_multiple()
  • A hook_update_N() to get the NID into Pane configuration for widgets that were already placed on existing sites
dsnopek’s picture

Assigned: dsnopek » Unassigned
StatusFileSize
new6.09 KB
new2.34 KB

Alright! This should be finished, but could use more testing. I'll run on Travis-CI in a moment too.

EDIT: Here's the Travis-CI build: https://travis-ci.org/dsnopek/panopoly/builds/50132238

dsnopek’s picture

Status: Needs review » Fixed

Tests on Travis are passing!

Reading through the issue summary, my patch doesn't fix all the problems that I was hoping to fix with this. In particular this one:

So, if two nodes have the same title, you can't pick one or the other. Or, if the title you want is a subset of another title, it sometimes favors the other, rather than the exact match.

But I could definitely imagine a way that the functionality from this patch could be extended to fix that as well! Since this patch already has the big conversion working, I'm going to commit and move solving that to #2108821: Problems selecting specific "Content item" when titles are the same or similar

Committed!

  • dsnopek committed 1368792 on 7.x-1.x
    Updated Panopoly Widgets and Test for Issue #2334439 by dsnopek: Switch...

Status: Fixed » Closed (fixed)

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