1

I would like to setup an environment where each of my users will be creating a node every day. I know all of my users won't be able to log in every day and they will want to check what they added on past days. I figured the best way to accomplish adding past days & displaying created content would be checking the url and returning either the node (if they have created one) or the node/add form if they have not.

For example, user 1234 navigates to: url = example.com/user/1234/2011/09/10

If they have a node created with a date field set to this day it would show the node. If not, it returns the node/add form with a hidden field set to the date in the url (easy, I can take care of that).

My first thought was panels/page manager, but I don't see a way to check if a node is created based on a date structure, if it can be accomplished I am all ears. If you think another solution is better... I am all ears!

EDIT: It has been brought to my attention that my original question overlooked a node type. I might have more than one, and I could see this being useful for other people so lets say for arguments sake that the url looks like this:

example.com/user/1234/[node-type]/2011/09/10

  • There are many type of nodes, what do you do about that? You can probably solve your problem using Rules module. – ram4nd Sep 12 '11 at 7:00
  • You are absolutely correct. In my final use case it would be a custom node type. I will modify my question. – Chance G Sep 12 '11 at 7:15
  • I assume you want to do what you wrote in title. Did you try Rules module? – ram4nd Sep 14 '11 at 7:07
  • I've used rules in the past but it didn't seem like the best solution in my head :) . How would you setup this rule? I'm assuming you would do some kind of check on the url/node. But would you recommend checking against a 'date field' or just the creation date of the node? Would it be a redirect to node/add/type? – Chance G Sep 14 '11 at 7:24
  • I don't know how to do what you need, all I know is that if you don't want to write code Rules module is probably the safest bet. – ram4nd Sep 16 '11 at 7:18
2

I ended up getting this to work with views, date and some custom code. Basically I created a page view that with a conditional filter for a post date in YYYYMMDD format (a default argument provided by date), if one didn't exist I added some code in the "No Results" field that would load the node creation form with basically:

$form = node_add(arg(0));
print drupal_render($form);

So a url of /story/20110915 would show the story from that date if it existed, otherwise it would show the node/add form for the story content type.

In the final product I actually had the view load an .inc file from my custom module in the "No Results" field (also much faster than editing the view every time while developing). But I think this gets the basic point across.

Sorry @ram4nd if I made it seem like I didn't want to write code, I just was looking for the best approach. So far this seems like it is pretty solid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.