Hi,

I looked through the Event's module code and I am not able to figure out how to add an 'Add an Event" link to the bottom of the Upcoming Events Block. It looks pretty easy to do, but I'm not too familar with PHP. Can anyone help? Thanks,

icon123

CommentFileSizeAuthor
#5 add_event.txt612 bytesnancydru

Comments

zaboomafoozarg’s picture

You could probably do this by creating a theme-specific function replacement in your theme's template.php. The HTML for upcoming events is generated by a number of functions in /modules/event/event.theme -- specifically, theme_event_upcoming_item, theme_event_upcoming_block, theme_event_ical_link, and theme_event_more_link. These are all called and their output combined together in the function event_block_upcoming in /modules/event/event.module.

Since the "more" link is shown last, you could create your own event_more_link function that would be used instead of theme_event_more_link.

Assuming your theme name is mytheme, edit /themes/mytheme/template.php and create a function:

function mytheme_event_more_link($path) {
}

Then call the existing function to generate the more link, and add the code for the "Add an Event" after that. Like so:

function mytheme_event_more_link($path) {
  $output = theme_event_more_link($path);
  $output .= '<div class="myaddeventlink"><a href="/node/add/event">Add an Event</a></div>';
  return $output;
}

Now when Drupal wants to generate the Upcoming events block it will run your mytheme_event_more_link function, create the more link using theme_event_more_link function, then tack on a div and link after that which lets a user add an event. Of course, you'd have to make the div, and you might have to check to see if the user is allowed to add an event as well.

icon123’s picture

Thanks for the follow up, but I'm still a little lost...

My theme doesn't come with a template.php file. I created one and tried putting the code in other php files I had in the 'mytheme' directory. None of it worked, probably because I didn't add any div tags.

Now for the embarrassing questions. Do both parts of the code you supplied go into the template.php?
I kind of understand what the Div tags are suppose to do, but I need a hint on what I do with them in this case?

I know these are pretty basic questions that I shouldn't be asking here, so if you don't want to or don't have time to further the lesson, I understand.

Thanks for the support thus far.

nancydru’s picture

@zaboomafoozarg - I think you missed his point. This is not really something that should be forced into a theme.

This is something that I've been seeing a lot lately: People can't figure out to use "create content" to do these things. The module developer or webmaster has to add an "add xxx" link to her/his already existing pages.

However, @icon123, the problem with doing this is that there can be many content types that are event-enabled, so which type do you want to add? I'm afraid this one is going to require user training...

icon123’s picture

Thanks Nancy for the follow up.

I want to have a simple link that points to node/add/event. I currently created one in a seperate block below the 'upcoming events' block. But to have a seperate block to do this is a waste and doesn't flow right. I don't have or want any generic 'create content' links or menus on the web page. Outside of having the link in the 'upcoming events' block I wouldn't mind having it below the montly calendar view in the 'Events' block. Either one seems hard to figure out.

I have already modified the recipe module block and the blog module block to do the same thing. However, with my limited php code knowledge, I can't quite figure out how to do it for the Event module. You are right in regards that I rather not do it via theme hacking, however I am willing to do what it takes to get that link added.

Since I am new here, I don't want to start throwing any weight around, but I can't believe this isn't something that other users wouldn't find of value. Maybe it's just the way I'm laying out the website. Thanks again,

icon123

nancydru’s picture

StatusFileSize
new612 bytes

As I trie to explain, on my site, and many others, I have Community Events, Events, and Holidays that are all event-enabled. Adding a link to that block as you dsecribe would only allow me to create an "Event" and not the other two. That's the problem. I understand your requirement and was working on a patch for you when I realized this problem.

I'm attaching a patch for you, but it's not useful to those of us who have multiple event types. It applies to the event.theme file.

icon123’s picture

Status: Active » Closed (fixed)

Yes, now I understand, I only have/need one Event content type. Well thanks for taken the time to work up that patch. I was able to figure out what it was changing/doing and modified it to do exactly what I wanted. It also taught me a little more about the Drupal structure and some additional php coding. I was only concentrating on the module file and never thought to look into the theme file. Thanks again for the help and lesson even if I will be the only person that benefits from this.

icon123

jhofer’s picture

Thank you NancyDru - you've enlightened me by posting that patch...