With the code below, I am able to publish my minutes with an alias such 'minutes/2007/04/05' - the date values come from the event associated with the minutes.

Index: modules/minutes/minutes.module
===================================================================
--- modules/minutes/minutes.module      (revision 4022)
+++ modules/minutes/minutes.module      (working copy)
@@ -676,3 +676,59 @@
 function minutes_views_default_views() {
 }
 
+/**
+* Implement pathauto hook to define minutes node placeholders
+*
+* @param string $op
+* @param object $node
+*/
+function minutes_pathauto_node($op, $node = NULL) {
+
+  switch ($op) {
+    case 'placeholders':
+      return array(
+        t('[minutes_eventyyyy]') => t('The year of an event associated with a minutes node.'),
+        t('[minutes_eventmm]') => t('The month of an event associated with a minutes node.'),
+        t('[minutes_eventdd]') => t('The day of an event associated with a minutes node.'),
+      );
+    break;
+    
+    case 'values':
+      $results = array();
+      switch ($node->type) {
+        case 'minutes':
+          $results[t('[minutes_eventyyyy]')] = _minutes_date($node, 'minutes_eventyyyy');
+          $results[t('[minutes_eventmm]')] = _minutes_date($node, 'minutes_eventmm');
+          $results[t('[minutes_eventdd]')] = _minutes_date($node, 'minutes_eventdd');
+          return $results;
+        break;
+      }
+    break;
+  }
+}
+
+/**
+* Substitute minutes pathauto placeholders with values from event
+*
+* @param object $node Minutes node
+* @param string $placeholder Placeholder to substitute
+* @return string Partial date value
+*/
+function _minutes_date($node, $placeholder) {
+
+  $event = node_load($node->event_id);
+  
+  switch($placeholder) {
+    case 'minutes_eventyyyy':
+      return date('Y', $event->event_start);
+    break;
+    
+    case 'minutes_eventmm':
+      return date('m', $event->event_start);
+    break;
+    
+    case 'minutes_eventdd':
+      return date('d', $event->event_start);
+    break;
+  }
+}

Comments

mightyiam’s picture

So one can't control the minute's paths with pathauto? Or is this a way to be able to use the associated event date?

jonathan_hunt’s picture

Sorry, missed your post. You can control minute's paths with pathauto like any other node. This exposes the associated event data; IMHO this makes for more useful URLs. It needs to be updated to work with the new pathauto API and token module though.

mightyiam’s picture

Oh i get it. Excellent.

jonathan_hunt’s picture

I've updated my placeholders code to work with Pathauto 2.x and Token module:

/**
* Substitute minutes pathauto placeholders with values from event
*
* @param object $node Minutes node
* @param string $placeholder Placeholder to substitute
* @return string Partial date value
*/
function _minutes_date($node, $placeholder) {
  $event = node_load($node->event_id);
  
  // Get the event start time as a Unix timestamp
  $event_start = $event->event_start;
  if (is_numeric($eventstart)) {
    $event_start = (int)$eventstart;
  }
  elseif (is_string($eventstart)) {
    $event_start = strtotime($event->event_start);
  }

  switch($placeholder) {
    case 'minutes_eventyyyy':
      return date('Y', $event_start);
    break;
    
    case 'minutes_eventmm':
      return date('m', $event_start);
    break;
    
    case 'minutes_eventdd':
      return date('d', $event_start);
    break;
  }
}

/*
 * Implementation of hook_token_list()
 */
function minutes_token_list($type = 'all') {
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['minutes_eventyyyy']  = t("The four-digit year of an event associated with a minutes node.");
    $tokens['node']['minutes_eventmm']    = t("The two-digit month (01-12) of an event associated with a minutes node.");
    $tokens['node']['minutes_eventdd']    = t("The two-digit day (01-31) of an event associated with a minutes node.");
    return $tokens;
  }
}

/*
 * Implementation of hook_token_values(). Expects object to be a Minutes node
 */
function minutes_token_values($type, $object = NULL) {
  
  if ($type == 'node') {
    $tokens['minutes_eventyyyy'] = _minutes_date($object, 'minutes_eventyyyy');
    $tokens['minutes_eventmm']   = _minutes_date($object, 'minutes_eventmm');
    $tokens['minutes_eventdd']   = _minutes_date($object, 'minutes_eventdd');
    
    debug(__FUNCTION__ .': returning tokens='. print_r($tokens, TRUE));
    return $tokens;
  }
}
robertgarrigos’s picture

Status: Active » Closed (duplicate)

I've added a patch with token support before I saw your code. As It's best to provide patches, I included your code in my patch: http://drupal.org/node/258804