After upgrading to Pathauto 2.0 Beta 1, I noticed that the tokens provided by the Event module (version 1.0) for the "Node path settings" patterns no longer show up:

  • eventyyyy
  • eventmm
  • eventmon
  • eventdd
  • eventday
  • eventweek

They were present in Pathauto 1.2, the last version I was using before upgrading to 2.0 Beta 1.

Comments

greggles’s picture

Project: Pathauto » Event
Category: bug » feature

This should be filed against the event module, not pathauto.

Workaround:
if you need the even patterns then use the 5.x-1.2 version of Pathauto.

Wolfey’s picture

My fault - the Event module I was using wasn't updated since I went from Pathauto 1.2 to 2.0 Beta 1, and since that was the only module I updated at this time, I assumed the issue was with Pathauto, instead of Event.

I'll keep that in mind about using Pathauto 1.2 if I need the Event tokens when setting up patterns - thanks for mentioning that.

greggles’s picture

Status: Active » Fixed

I committed a fix which renamed the functions. I'd still rather have these in the event module, but will provide the best options I can until then.

Wolfey’s picture

Thank you for adding this to Pathauto, greggles - I really appreciate it =)

greggles’s picture

So, does that mean you can confirm that it works? ;)

I didn't test it...

Wolfey’s picture

Good thing you mentioned that - I forgot to try it out to ensure it's working properly!

Unfortunately, there is a problem - it shows the same values (all corresponding to the Unix epoch) when testing it out with "Event" nodes, regardless of the starting date:

  • eventyyyy: 1969
  • eventmm: 12
  • eventmon: dec
  • eventdd: 31
  • eventday: wed
  • eventweek: 1
greggles’s picture

Status: Fixed » Active

Well, now it really is up to the event module (or someone who knows event, rather) to maintain that part.

bluecobalt’s picture

I can confirm that it doesn't work yet. All dates showing up as Dec 31 1969.

bluecobalt’s picture

Category: feature » bug

Is anyone working on fixing this?

greggles’s picture

I'd say that having the "Assigned" field empty and my response that I'm not working on it gives a clear indication that I'm not and nobody else is so far - feel free to debug and find a solution.

Wolfey’s picture

I'm not sure if this would help with the issue, but in pathauto_node_event.inc (1.3.4.4), lines 23-33 read:

function event_token_values($type, $object = NULL) {
  if ($type == 'node') {
    $tokens['eventyyyy']      = date('Y', $eventstart);
    $tokens['eventmm']      = date('m', $eventstart);
    $tokens['eventmon']      = pathauto_cleanstring(date('M', $eventstart));
    $tokens['eventdd']      = date('d', $eventstart);
    $tokens['eventday']      = pathauto_cleanstring(date('D', $eventstart));
    $tokens['eventweek']      = date('W', $eventstart);
    return $tokens;
  }
}

Out of curiosity, I checked to see if there was anything in "$eventstart":

if ($eventstart == null) {
  echo "This variable is empty.";
}
else {
  echo "This variable is not empty.";
}

According to that, it's empty, as the first statement is shown - this also happens with nonexistent variable names as well. To make sure it wasn't a false alarm, I replaced "$eventstart" with a non-empty variable (in this case, "$node"), and got the second statement (that it's not empty)...so it appears there may be something wrong with the "$eventstart" variable.

Could it be empty or nonexistent? It could help explain why the date values are always the same, as I can achieve the same outcome with by replacing all occurrences of "$eventstart" with a nonexistent variable in the file above.

Also, after using the "Devel" module to check out an event I had created, it seems that "$node->event['start']" has all of the necessary information for getting this to work. Would it be possible (even as a temporary hack) to extract the year/month/day values from that and assign them to the "Event" tokens for use with Pathauto?

gerhard killesreiter’s picture

Category: bug » feature

This needs a patch.

function event_token_values($type, $object = NULL) {
  if ($type == 'node') {
    $tokens['eventyyyy']      = date('Y', $eventstart);
    $tokens['eventmm']      = date('m', $eventstart);
    $tokens['eventmon']      = pathauto_cleanstring(date('M', $eventstart));
    $tokens['eventdd']      = date('d', $eventstart);
    $tokens['eventday']      = pathauto_cleanstring(date('D', $eventstart));
    $tokens['eventweek']      = date('W', $eventstart);
    return $tokens;
  }
}

This is very obviously broken, $eventstart isn't even defined.

If $object is a fully loaded node object, then you are probably lookign for $node->event['start'].

Feed this into event_format_date which has the same syntax as format_date. File patch. Done.

Wolfey’s picture

I read what you said, but I'm still confused:

  • Does "$eventstart" need replaced since it isn't defined?
  • Is "$object" supposed to be replaced with "$node->event['start']"?
  • How would it be fed into "event_format_date" when that code is mentioned in a completely different file ("event.module", instead of "pathauto_node_event.inc")?

I apologize if these are dumb questions - I only have a basic understanding of PHP, so I really have no idea how to implement the changes you mentioned.

HorsePunchKid’s picture

I upgraded to pathauto 5.x-2.0-beta2, and I'm trying to get my event paths working again, too. I'm having trouble figuring out the execution path, really. It doesn't appear that any of the functions in pathauto/contrib/pathauto_node_event.inc actually get called, which makes me suspect that it's not using the current pathauto API.

If anyone has any suggestions on where to go for API documentation or a relevant code example--given that neither the code in contrib nor pathauto/pathauto_*.inc has helped much so far--I would be very greatful.

I think I'm on an outdated version of the event module, too, but I'll post anything I come up with that appears to work.

HorsePunchKid’s picture

Wolfey, I think Gerhard is suggesting placing something like this at the top of event_token_values:

$eventstart=event_format_date($object->event['start']);

I guess I would need to upgrade my install of the event module to test that out for you, though. I'm still concerned that those functions don't even seem to get called.

Gerhard, is there a relatively stable version I should upgrade to? I'm sorry, I haven't kept up with the progress being made on the module.

HorsePunchKid’s picture

StatusFileSize
new1.57 KB

Well, it was not so complicated as I expected. This patch will likely not work for you if you're using the 2.x branch of the event module, but something similar might. The key was that the functions in pathauto_node_event.inc no longer had the correct names, but I also needed to get $eventstart from the $object, and a similar modification will be needed for event 2.x as Gerhard suggested.

gerhard killesreiter’s picture

Status: Active » Needs work

yeah, this is in the rigth direction. :)

greggles’s picture

Status: Needs work » Fixed

Thanks HorsePunchKid - committed to the 5.x-2.x branch. Please make your patches against the tip of the branch (i.e. I already fixed the function naming problem...)

@Gerhard - one reason for implementing this in Event rather than in Pathauto is that you could then have control over the data structures on the different branches. I can only do one so I'm staying with the 1.x version (apparently).

bluecobalt’s picture

Status: Fixed » Active

Okay, so this probably works with the 1.0 branch of the event module.

What about the 5.x-2.x-dev version?

greggles’s picture

Active indeed. Due to this fatal error I've removed the code from pathauto.

If someone wants to provide it as a patch for event module, great. But I don't need fatal errors in pathauto related to some other module :p

HorsePunchKid’s picture

StatusFileSize
new3.41 KB

I have gotten this working again. From what I gather, what really needed to happen is that event.module needed to get updated to implement the proper hooks, one for pathauto to do the replacing and two for token to get tokens and values. I'm not sure what the relation between the two is or is supposed to be, but I suspect I can simplify this patch.

I think I should file an issue for the event module. I'm running a HEAD version of it from sometime in March, so I'm not sure exactly what this will apply to. It should basically work for any 1.x release of event. Getting it working with the 2.x releases should just be a matter of a function call to parse or format the event start date.

HorsePunchKid’s picture

Sorry, I didn't notice that this issue is actually under the event project, not the pathauto project; please disregard that part of my message.

HorsePunchKid’s picture

Title: Tokens (Event Module): Missing Tokens Following Upgrade » Tokens missing after upgrade to Pathauto 2.0 beta
Status: Active » Needs review
StatusFileSize
new2.01 KB

Here is a much cleaner patch.

kenorb’s picture

HorsePunchKid:
Try to patch this patch changing below lines:

      $results[t('[eventyyyy]')] = date('Y', strtotime($eventstart));
      $results[t('[eventmm]')] = date('m', strtotime($eventstart));
      $results[t('[eventmon]')] = pathauto_cleanstring(date('M', strtotime($eventstart)));
      $results[t('[eventdd]')] = date('d', strtotime($eventstart));
      $results[t('[eventday]')] = pathauto_cleanstring(date('D', strtotime($eventstart)));
      $results[t('[eventweek]')] = date('W', strtotime($eventstart));

you need to use strtotime() function.
That's why some people has problem with 1970 year.

HorsePunchKid’s picture

If I do strtotime there, then I start to get 1969/12/31 instead. What version of the module are you using? I'm using a dev version of 1.x. Maybe 2.x needs that extra function call?

kenorb’s picture

I think that it depends what version of Event you use.
Before there was datetime format in mysql (event table), in new version (2.x) there is timestamp format.
Second argument of date function must be in timestamp format.
So I think that for compatibility for both of versions this function should check in which format is a $eventstart variable (e.g. using is_string() function) and to make sure that second argument is in timestamp format.
But, whatever, I'll be not investigated that.

kenorb’s picture

StatusFileSize
new460 bytes

My proposition is change line from:

      $eventstart = $object->event_start;

to:

      $eventstart = is_string($node->event_start) ? strtotime($node->event_start) : $node->event_start;

Should work in both version of Event.

Before I got:
* Repeat settings updated
* Created new alias course_dates/event+1970+01+01 for node/712
* Your Course Date has been created.
After change:
* Repeat settings updated
* Created new alias course_dates/event+2007+10+10 for node/715
* Your Course Date has been created.

In attachment there is patch for people who using still old version of Pathauto (with contrib/pathauto_node_event.inc file) with new version of Event (2.x).

HorsePunchKid’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.08 KB

Good idea, kenorb. I have made the change you suggested (the only difference being that $node should be $object), and it's working fine on my event-5.x-1.x version.

bluecobalt’s picture

Hmmm...

None of these patches work for me. Using Events 2.0 and Pathauto 1.0 or 2.0, I still get 1969/12/31 for the date.

HorsePunchKid’s picture

Status: Reviewed & tested by the community » Needs work

I'll set up a test site for event-5.x-2.x and see what happens. I'm still on 1.x, and I have been assuming kenorb is on 2.x, so I thought we had all the bases covered. If you want to help debug, you could tell me what the output is after when you add drupal_set_message(var_export($eventstart,TRUE)); after the $eventstart = is_string(... line in event.module.

bluecobalt’s picture

Woohoo!

HorsePunchKid, your last patch, event_pathauto_28.patch, works but has a typo in it that has to be corrected for it to work.

$eventstart = is_string($object->event_start) ? strtotime($object->event_start) : $object->event_start;;

has an extra semicolin at the end and should be

$eventstart = is_string($object->event_start) ? strtotime($object->event_start) : $object->event_start;

Event 2.0 then works fine with Pathauto 2.0, and gives the correct date.

HorsePunchKid’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2.08 KB

Interesting! I'm scratching my head trying to figure out why an extra semicolon would cause it to misbehave, but thank you for spotting the typo, in any case. Here's the same patch but with the extra semicolon obliterated.

bluecobalt’s picture

The plot thickens.

It works if you create a new event node, or update an existing one, but the bulk generation of url aliases byt Pathauto still gives 1969/12/31.

HorsePunchKid’s picture

Can you file a new bug report for that problem? I'd really like to see this issue get closed out, because with this patch, it's at least better than having %5Beventweek%5D showing up in your URLs. :)

greggles’s picture

Status: Reviewed & tested by the community » Needs work

The "only works during insert/edit" is a common problem. The new node has a particular data structure that is determined mostly by the FAPI code for the node submission form.

The bulk generation is based on a "node_load" of the node which may put data into other places. The solution is to check for the element in a specific location (i.e. where it is during node creation/edit) and if it's not found there then test the location of the data after a "node_load" and try to use that.

If neither exists, well, we end up with 1969 but that is usually a misconfiguration on the part of the admin.

HorsePunchKid’s picture

To clarify, is the problem that when calling event_token_values(), the $type of the $object is something other than 'node', or is it still a 'node' but just with a slightly different structure?

Wolfey’s picture

Just got around to trying out your patch, HorsePunchKid - after it was applied, I changed the Pathauto pattern for events back to what it was before (to use the tokens I mentioned in the start of this topic).

After doing that, followed by editing event nodes and resubmitting them (to force their paths to be updated), my event URLs now show the correct date =D

greggles’s picture

@horsepunchkid - it's still a node object, but it has a different data structure.

HorsePunchKid’s picture

Priority: Normal » Critical
Status: Needs work » Needs review
StatusFileSize
new2.2 KB

Here's a patch that works during add/edit and during bulk updates for event-5.x-1.0. Can interested parties test against other versions?

It turns out we were getting the Unix timestamp as a string, so we needed to check for is_numeric().

HorsePunchKid’s picture

Status: Needs review » Reviewed & tested by the community

I've just tested this against event-5.x-2.x-dev during add/edit and bulk update, and it appears to be working fine.

ksenzee’s picture

I've successfully tested against event-5.x-1.0. Thanks for the patch.

killes@www.drop.org’s picture

committed to 5.2. Is this needed for 5.1 as well?

HorsePunchKid’s picture

Yes, this is needed for 5.1, too. I'm not sure if the patch will apply properly, but it's just those two functions that need to end up in event.module somewhere, presumably at the bottom.

rmiddle’s picture

I just tried this patch in Current Pathauto/token/Events/Repeats Events. It works well. I would Sugest a backport to 5.x-1.x as well.

Thanks
Robert

greggles’s picture

Marked http://drupal.org/node/219515 as a duplicate of this.

csc4’s picture

Confirm patch works well for me too.

A backport to 5.1 would be very gratefully received.

rmiddle’s picture

What is the status of this Patch?

Thanks
Robert

csc4’s picture

I've just realised that this could also do with the complementary event ends tokens...

Something like

/*
 * Implementation of hook_token_values()
 */
function event_token_values($type, $object = NULL) {
  if ($type == 'node') {
    // Get the event start time as a Unix timestamp
    $eventstart = $object->event_start;
    if (is_numeric($eventstart)) $eventstart = (int)$eventstart;
    elseif (is_string($eventstart)) $eventstart = strtotime($object->event_start);

    $eventend = $object->event_end;
    if (is_numeric($eventend)) $eventend = (int)$eventend;
    elseif (is_string($eventend)) $eventend = strtotime($object->event_end);
    
    if ($eventend < $eventend) $eventend = $eventstart;

    $tokens['event_start-yyyy'] = date('Y', $eventstart);
    $tokens['event_start-yy'] = date('y', $eventstart);
    $tokens['event_start-mm']   = date('m', $eventstart);
    $tokens['event_start-mon']  = date('M', $eventstart);
    $tokens['event_start-dd']   = date('d', $eventstart);
    $tokens['event_start-j']   = date('j', $eventstart);
    $tokens['event_start-day']  = date('D', $eventstart);
    $tokens['event_start-week'] = date('W', $eventstart);

    $tokens['event_end-yyyy'] = date('Y', $eventend);
    $tokens['event_end-yy'] = date('y', $eventend);
    $tokens['event_end-mm']   = date('m', $eventend);
    $tokens['event_end-mon']  = date('M', $eventend);
    $tokens['event_end-dd']   = date('d', $eventend);
    $tokens['event_end-j']   = date('j', $eventend);
    $tokens['event_end-day']  = date('D', $eventend);
    $tokens['event_end-week'] = date('W', $eventend);

    return $tokens;
  }
}

Perhaps?

Also has this been backported to 5.1?

karunadave’s picture

Version: 5.x-2.x-dev » 5.x-1.x-dev

I have been sitting with pathauto 1.2 hoping this will be resolved someday.

Look what I just found that will help with this: a module called Event Token http://drupal.org/node/233769/release.

csc4’s picture

That's a good find. Wonder which this 'ought' to go in?

Also been thinking we need the time ones too as well as the date.

nasi’s picture

Confirm patch works for me on event-5.x-1.0

Is that enough testing for this to be committed yet?

vkr11’s picture

karunadave’s picture

It may be more fruitful to use CCK date which does produce tokens that do this.

rmiddle’s picture

#53 Karunadave,

Part of the reason to use Events is to avoid using CCK. Why make CCK a requirement of a module. It doesn't make any since.

Thanks
Robert

konsumer’s picture

I never saw this issue, and made my own module, with the hope that it would eventually be integrated into Event:
http://drupal.org/project/event_tokens

It adds quite a few more tokens, but otherwise is pretty similar to what is in here.

I'd be super-psyched to integrate this.

kenorb’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
japerry’s picture

Status: Patch (to be ported) » Closed (outdated)

Event for Drupal 8 is unrelated to older versions. If an issue similar to this one exists, please open a new issue with the 8.x branch.