You are here

og_theme.module in Organic groups theme 7

Same filename and directory in other branches
  1. 7.2 og_theme.module

Associate theme to a group.

File

og_theme.module
View source
<?php

/**
 * @file
 * Associate theme to a group.
 */

/**
 * Group theme field.
 */
define('OG_THEME_FIELD', 'group_theme');

/**
 * Implement og_fields_info().
 */
function og_theme_og_fields_info() {
  $items[OG_THEME_FIELD] = array(
    'type' => array(
      'group',
    ),
    'description' => t('Associate theme to a group.'),
    'field' => array(
      'field_name' => OG_THEME_FIELD,
      'no_ui' => TRUE,
      'type' => 'list_text',
      'cardinality' => 1,
      'settings' => array(
        'allowed_values' => array(),
        'allowed_values_function' => 'og_theme_field_allowed_values',
      ),
    ),
    'instance' => array(
      'label' => t('Groups theme'),
      'widget_type' => 'options_select',
      'required' => TRUE,
      // Use default theme as default value.
      'default_value' => array(
        0 => array(
          'value' => '__default',
        ),
      ),
      'view modes' => array(
        'full' => array(
          'label' => 'above',
          'type' => 'list_default',
        ),
        'teaser' => array(
          'label' => 'above',
          'type' => 'list_default',
        ),
      ),
    ),
  );
  return $items;
}

/**
 * Implements hook_custom_theme().
 *
 * Change the theme, based on a group context.
 */
function og_theme_custom_theme() {
  if ($group = og_context()) {

    // Load the entity.
    $entity = $group
      ->getEntity();

    // Check if a theme field exists, and it isn't defined as "default"
    // (i.e. use the default site theme).
    if (!empty($entity->{OG_THEME_FIELD}[LANGUAGE_NONE][0]['value']) && $entity->{OG_THEME_FIELD}[LANGUAGE_NONE][0]['value'] != '__default') {
      return $entity->{OG_THEME_FIELD}[LANGUAGE_NONE][0]['value'];
    }
  }
}

/**
 * Return all enabled themes.
 */
function og_theme_field_allowed_values() {
  $return = array(
    '__default' => t('Use site-wide theme definition'),
  );
  module_load_include('inc', 'system', 'system.admin');
  $themes = list_themes();
  uasort($themes, 'system_sort_modules_by_info_name');
  foreach ($themes as $key => $value) {
    if ($value->status) {
      $return[$key] = check_plain($value->info['name']);
    }
  }
  return $return;
}

Functions

Namesort descending Description
og_theme_custom_theme Implements hook_custom_theme().
og_theme_field_allowed_values Return all enabled themes.
og_theme_og_fields_info Implement og_fields_info().

Constants

Namesort descending Description
OG_THEME_FIELD Group theme field.