You are here

_hijri.module in Hijri 8

File

_hijri.module
View source
<?php

/**
 * Implements hook_block_info().
 */
function hijri_block_info() {

  // This example comes from node.module.
  $blocks['hijri'] = array(
    'info' => t('Hijri Date Block'),
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function hijri_block_view($delta = '') {

  // This example is adapted from node.module.
  $block = array();
  switch ($delta) {
    case 'hijri':
      $block['subject'] = t('Hijri Date');
      $block['content'] = _hijri_date_block();
      break;
  }
  return $block;
}

/**
 * The callback of Hijri date block to display the type of date selected.
 */
function _hijri_date_block() {
  $correction = variable_get('hijri_correction_value', 0);
  $hijri_value = variable_get('hijri_display_block');
  $format = hijri_format_date(time(), $hijri_value, NULL, $correction);
  $content = theme('hijri_date', array(
    'data' => $format,
  ));
  return $content;
}

/**
 * Implements hook_theme().
 */
function hijri_theme($existing, $type, $theme, $path) {
  $item = array();
  $item = array(
    'hijri_date' => array(
      'variables' => array(
        'data' => Null,
      ),
      'template' => 'hijri-date',
      'path' => drupal_get_path('module', 'hijri') . '/theme',
    ),
  );
  return $item;
}

/**
 * Form submit handler.
 */
function hijri_settings_form_submit($form, &$form_state) {

  // Check if our field is not already created.
  if (!field_info_field('field_hijri_correction')) {

    // Create the field base.
    $field = array(
      'field_name' => 'field_hijri_correction',
      'type' => 'number_integer',
    );
    field_create_field($field);
  }
  foreach ($form_state['values']['hijri_types'] as $key => $type) {

    // Create the instance.
    $instance = array(
      'field_name' => 'field_hijri_correction',
      'entity_type' => 'node',
      'bundle' => $key,
      'label' => t('Hijri Date Correction'),
      'description' => t('This field will save the Correction and different between months'),
      'required' => FALSE,
    );
    if ((string) $type == (string) $key) {
      $prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
      if (empty($prior_instance)) {
        field_create_instance($instance);
      }
    }
    else {
      $prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
      if (!empty($prior_instance)) {
        field_delete_instance($instance, FALSE);
      }
    }
  }
}

/**
 * Implements hook_node_presave().
 */
function hijri_node_presave($node) {
  $node_types = variable_get('hijri_types', array());
  foreach ($node_types as $type) {
    if ($node->type == $type) {
      $node->field_hijri_correction[$node->language][0]['value'] = variable_get('hijri_correction_value', 0);
    }
  }
}

/**
 * Implements hook_views_api().
 */
function hijri_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'hijri') . '/views',
  );
}

/**
 * Implements hook_node_view().
 */
function hijri_node_view($node) {
  unset($node->content['field_hijri_correction']);
}

Functions

Namesort descending Description
hijri_block_info Implements hook_block_info().
hijri_block_view Implements hook_block_view().
hijri_node_presave Implements hook_node_presave().
hijri_node_view Implements hook_node_view().
hijri_settings_form_submit Form submit handler.
hijri_theme Implements hook_theme().
hijri_views_api Implements hook_views_api().
_hijri_date_block The callback of Hijri date block to display the type of date selected.