Hi,

I've started to review the Panels integration in CCK, and while CCK can expose fields and fieldgroups to Panels, the node title and body seem to live on no mans land. Well, I was not able to see if node title and body can be used in panels as independent "content types".

Sorry if I'm not using the correct lingo. And sorry if that's already possible in Panels 3. I just started to look at it quite recently.

So, if not already possible, my question would be: who should expose the panel content types to be able to use node title and body as independent content providers in panels? It could be done by Panels node integration or it could be done by CCK. Which one should? If it has to be CCK, then I'll code that in CCK. :) If it has to be Panels itself, then I may try to provide a patch, but I would appreciate some hints as I'm still learning Panels. :-/

Thanks

Comments

markus_petrux’s picture

I bit more thoughts... if we look at how this is approached in views, it is views who exposes the node core fields itself. So, aside from needing to show the title and body fields as separate content types in panels, maybe it is also needed to do the same for other node core fields in the node, such as the author, created date, etc.

So... it seems it would make more sense if it was Panels who exposes these fields as independent Panels "content types"?

merlinofchaos’s picture

Your thoughts in #1 are exactly right, I think.

markus_petrux’s picture

So I guess it should be implemented by ctools, in the directory ctools/plugins/content_types/node_context, as a separate file named node_fields.inc? And here we can start exposing the node title, body, created, changed and node author (with an option to link to the user profile).

Sounds good? Or do you already have plans for this? I have a bare idea on how to do it, but I may try to, if that helps.

merlinofchaos’s picture

I do not have any more specific plans than what you've stated, and every since the CCK fields went in this has definitely been needed.

merlinofchaos’s picture

And I forgot to type: Yes, your proposal sounds exactly correct. The fields presented should be easy enough to do, as the output is very simple. Take the node context, extract the data, run it through the proper XSS filter, and return it.

It is probably not much more complicated than node_type_desc.inc, except for the fact that you do need subtypes so you can offer each field. Though honestly, each field could just be its own content type, too. That's actually a little simpler, and core fields don't change. It can also provide a very good guide for modules that have fields that are not CCK fields that they wish to expose via Panels.

markus_petrux’s picture

Here's one doubt:

The label for the title and body fields can be changed in the node type settings screen. Also, when the body label is left blank, then the body for that node type is not used.

Question: should we expose title and body for each node type as separate entities?

If yes, the label for these couple of entities exposed to Panels ought to be something like "@user-defined-label in @node-type"?

If no, should the label for these entities by simply "Title" and "Body"? (I don't like this)

If both, then what? :-/

Another doubt: what about the icons? May we start with 'icon_node.png' for all these elements?

markus_petrux’s picture

Project: Panels » Chaos Tool Suite (ctools)
Version: 6.x-3.x-dev » 6.x-1.x-dev
Component: Panel nodes » Code

BTW, I think this is ctools business.

markus_petrux’s picture

More thoughts on #6 about title/body:

It looks like we could expose just one title/body, and just let the admin provide a label. This would be similar behavior in views. However, in views you can add the title several times, each related to a relationship that points to a different node type, and you can label each "title" field according to the node type the field refers to. I'm not sure if this is possible in Panels.

Maybe like this? The title/body settings form, may ask if you want to relate this field to a particular node type, or just any. That way you can add title/body several times to a panel, each related to a node type, while the title/body fields are just exposed to panels once. You can choose which node type or any in the settings form. Sounds good?

merlinofchaos’s picture

I don't think we can. Then if you have 12 node types, and you have a node with no type associated, you'll get it listed 12 times. That's awful.

markus_petrux’s picture

StatusFileSize
new4.33 KB

Ok, here's an attached file that implements title, body, created and updated fields.

The file is aimed to be copied to ctools/plugins/content_types/node_context, and it should be renamed to node_fields.inc.

It's a start. Please, critique. :) Once this is in the right direction, we can add more fields, such as the node author, and may be that's enough for now.

markus_petrux’s picture

Status: Active » Needs review

Ah, just for reference. Latest development snapshots of CCK contain a reviewed implementation of the CCK fields integration, and also support for field groups, which is being enhanced here: #495582: Panels integration for multigroups

markus_petrux’s picture

StatusFileSize
new6.2 KB

File node_fields.inc updated. This one also implements node author and published status.

markus_petrux’s picture

AFAICT, I'm done adding node fields here. Is it ok like this, or should I change anything? Do you want me to add any other field? :-|

...or do you want separate content types as suggested in #5? I think I forgot and did it using subtypes, using the same approach as in CCK.

Once this is in, I may eventually try to do something similar for a couple of user fields: nickname and date registered / member for.

merlinofchaos’s picture

I prefer them in separate files for readability. It's a bit more hassle up front, but it's MUCH nicer when someone is looking through the files and sees just the minimum. I also found it difficult to maintain when I used to do node form stuff with this method. Otherwise, scanning through this it all seems pretty reasonable.

markus_petrux’s picture

StatusFileSize
new1.93 KB

Here's a first try for an individual node field template. Implements the node title. Please, let me know if it's ok.

markus_petrux’s picture

StatusFileSize
new1.92 KB

Updated to fix PHP issue. Sorry.

merlinofchaos’s picture

  $node = drupal_clone($context->data);

No point in this, nothing destructive is being done to the data. (I do this in rendering because node_view() is destructive.

Otherwise this is good.

markus_petrux’s picture

StatusFileSize
new2.02 KB

hmm... true.

Here's an updated copy. Here I'm using:

  // Get a shortcut to the node.
  $node = &$context->data;

..by reference, so PHP does not need to copy the object data.

If this is ok, then I'll prepare more fields as standalone content types.

Sorry for the doubts, but I like to be sure.

BTW, the other content type use this:

$node = isset($context->data) ? drupal_clone($context->data) : NULL;

where if there's no node, then something like $node->nid will fail. This might be something for a separate patch maybe?

merlinofchaos’s picture

No need to do that reference. if it's unnecessary; PHP won't copy the object unless changes are made. And in PHP5 it's more or less a reference anyway. Technically it's *more* overhead to use a reference when you don't actually need it. Strange, I know.

Do you want me to commit this one or do you want to put the rest together this same way?

markus_petrux’s picture

Ok, feel free to commit this one without the reference. Then leave this as "needs work", then I'll update when I have the other content types using the same exact pattern as you commit.

That way, I just don't need to update the node title again.

merlinofchaos’s picture

Status: Needs review » Needs work

Ok, node title committed!

markus_petrux’s picture

Oops! It seems the changelog was updated, but the new file was not added.

http://drupal.org/cvs?commit=238852

Reminder: the missing file is the one in #18 without the & to get the node by ref.

I'll post a few more content types for node fields later today.

markus_petrux’s picture

StatusFileSize
new11.16 KB

Well, I'm attaching a patch this time.

It includes the following content types:

- node_title
- node_body
- node_author
- node_created
- node_updated

So you can dismiss the files attached before. This patch contains everything, just following the same pattern as discussed.

There may be minor fixes that you may wish to apply, so please let me know if you wish me to make any other change.

markus_petrux’s picture

Status: Needs work » Needs review
merlinofchaos’s picture

Status: Needs review » Fixed

Ok, the patch was made in the wrong directory so initially the files went into the wrong place. But I got 'em committed on the second try.

markus_petrux’s picture

Status: Fixed » Needs review
StatusFileSize
new869 bytes

I would swear that the body was working when I tested, but now it's broken because it doesn't provide a settings form, an empty function seems to be enough.

In case it's not easy to fix this requirement elsewhere, attached patch fixes it here.

merlinofchaos’s picture

Status: Needs review » Fixed

Whoops. Nice one!

Hey, I want to give a BIG thanks for all the work you've been doing on this stuff lately. Your comments, criticisms and patches have helped make this a better project and I really appreciate it!

markus_petrux’s picture

Hey, you're welcome! ...also, thanks as well for your hard work in these monster modules! :)

Status: Fixed » Closed (fixed)

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