You are here

commerce_kickstart_blog.module in Commerce Kickstart 7.2

File

modules/commerce_kickstart/commerce_kickstart_blog/commerce_kickstart_blog.module
View source
<?php

/**
 * @file
 * Code for the Commerce Kickstart blog.
 */
include_once 'commerce_kickstart_blog.features.inc';

/**
 * Implements hook_migrate_api().
 */
function commerce_kickstart_blog_migrate_api() {

  // Only register the migration for demo store.
  if (variable_get('commerce_kickstart_demo_store', FALSE)) {
    return array(
      'api' => 2,
      'migrations' => array(
        'CommerceKickstartBlogPost' => array(
          'class_name' => 'CommerceKickstartBlogPost',
        ),
      ),
    );
  }

  // Return a near empty array to avoid API warning.
  // @link https://www.drupal.org/node/2544320
  return array(
    'api' => 2,
  );
}

/**
 * Implements hook_commerce_kickstart_crumb_info().
 *
 * Enables the Crumbs plugin relevant to this module that provides taxonomy
 * based breadcrumbs for each blog post.
 */
function commerce_kickstart_blog_commerce_kickstart_crumb_info() {
  return array(
    'taxonomy.termReference.field_blog_category.node.blog_post',
  );
}

/**
 * Override or insert variables into the page template.
 */
function commerce_kickstart_blog_preprocess_node(&$vars) {
  if ($vars['type'] == 'blog_post') {

    // Switching to short date format.
    $vars['date'] = format_date($vars['created'], 'short');

    // Override taxonomy path.
    if (array_key_exists('content', $vars)) {
      $content =& $vars['content'];
      if (array_key_exists('field_tags', $content)) {
        foreach ($content['field_tags']['#items'] as $index => $info) {
          $id = $info['tid'];
          $content['field_tags'][$index]['#href'] = 'blog/tags/' . $id;
        }
      }
      if (array_key_exists('field_blog_category', $content)) {
        foreach ($content['field_blog_category']['#items'] as $index => $info) {
          $id = $info['tid'];
          $content['field_blog_category'][$index]['#href'] = 'blog/category/' . $id;
        }
      }
    }
  }
}

Functions

Namesort descending Description
commerce_kickstart_blog_commerce_kickstart_crumb_info Implements hook_commerce_kickstart_crumb_info().
commerce_kickstart_blog_migrate_api Implements hook_migrate_api().
commerce_kickstart_blog_preprocess_node Override or insert variables into the page template.