You are here

layouter.module in Layouter - WYSIWYG layout templates 7

Same filename and directory in other branches
  1. 8 layouter.module

This module provide ability to add layout to text fields.

File

layouter.module
View source
<?php

/**
 * @file
 * This module provide ability to add layout to text fields.
 */

/**
 * Implements hook_menu().
 */
function layouter_menu() {
  $items = array();
  $items['admin/config/content/layouter'] = array(
    'title' => 'Layouter',
    'description' => 'Layouter settings.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'layouter_config_main_form',
    ),
    'access arguments' => array(
      'administer layouter',
    ),
    'file' => 'includes/layouter.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/layouter/%'] = array(
    'title' => 'Choose Layout',
    'page callback' => 'layouter_choose_layout',
    'page arguments' => array(
      2,
    ),
    'access callback' => TRUE,
    'file' => 'includes/layouter.pages.inc',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function layouter_permission() {
  $items = array();
  $items['administer layouter'] = array(
    'title' => t('Administer Layouter'),
    'description' => t('Allow to edit Layouter settings.'),
  );
  $items['use layouter'] = array(
    'title' => t('Use Layouter'),
    'description' => t('Allow to use Layouter for editing content.'),
  );
  return $items;
}

/**
 * Implements hook_theme().
 */
function layouter_theme($existing, $type, $theme, $path) {
  return array(
    'layouter_image_only' => array(
      'variables' => array(
        'image' => NULL,
      ),
      'template' => 'theme/tpl/image_only',
    ),
    'layouter_two_columns' => array(
      'variables' => array(
        'text' => NULL,
      ),
      'template' => 'theme/tpl/two_columns',
    ),
    'layouter_two_columns_img_left_text_right' => array(
      'variables' => array(
        'text' => NULL,
        'image' => NULL,
        'caption' => NULL,
      ),
      'template' => 'theme/tpl/two_columns_img_left_text_right',
    ),
    'layouter_two_columns_img_right_text_left' => array(
      'variables' => array(
        'text' => NULL,
        'image' => NULL,
        'caption' => NULL,
      ),
      'template' => 'theme/tpl/two_columns_img_right_text_left',
    ),
    'layouter_two_columns_text_img_left' => array(
      'variables' => array(
        'text' => NULL,
        'image' => NULL,
      ),
      'template' => 'theme/tpl/two_columns_text_img_left',
    ),
    'layouter_big_img_text_below' => array(
      'variables' => array(
        'text' => NULL,
        'image' => NULL,
      ),
      'template' => 'theme/tpl/big_img_text_below',
    ),
    'layouter_big_img_text_above' => array(
      'variables' => array(
        'text' => NULL,
        'image' => NULL,
      ),
      'template' => 'theme/tpl/big_img_text_above',
    ),
    'layouter_big_img_two_column_text_below' => array(
      'variables' => array(
        'text' => NULL,
        'image' => NULL,
      ),
      'template' => 'theme/tpl/big_img_two_column_text_below',
    ),
    'layouter_big_img_two_column_text_above' => array(
      'variables' => array(
        'text' => NULL,
        'image' => NULL,
      ),
      'template' => 'theme/tpl/big_img_two_column_text_above',
    ),
  );
}

/**
 * Implements hook_element_info_alter().
 */
function layouter_element_info_alter(&$types) {
  if (user_access('use layouter')) {
    $types['text_format']['#pre_render'][] = 'layouter_text_format_pre_render';
  }
}

/**
 * Processes textarea element if it is allowed to enable Layouter.
 */
function layouter_text_format_pre_render($element) {
  require_once 'includes/layouter.inc';
  $module_path = drupal_get_path('module', 'layouter');
  drupal_add_js($module_path . '/theme/layouter.js');
  drupal_add_css($module_path . '/theme/layouter.css');
  ctools_include('modal');
  ctools_modal_add_js();
  $active_text_formats = layouter_active_text_formats();
  $active_content_types = layouter_active_content_types();
  drupal_add_js(array(
    'layouter' => array(
      'active_text_formats' => $active_text_formats,
    ),
  ), 'setting');

  // Field collection integration.
  if (module_exists('field_collection')) {
    if (isset($element['#entity_type'])) {
      if ($element['#entity_type'] == 'field_collection_item' && !empty($element['#entity'])) {
        $host_entity = $element['#entity']
          ->hostEntity();
        if (!in_array($host_entity->type, $active_content_types)) {
          return $element;
        }
      }
    }
  }
  else {
    if (empty($element['#bundle']) || !in_array($element['#bundle'], $active_content_types)) {
      return $element;
    }
  }
  if (isset($element['value'])) {
    $element['value'] = layouter_load_by_field($element['value'], $element['format']['format']);
  }
  else {
    $element = layouter_load_by_field($element, $element['#format']);
  }
  return $element;
}

Functions

Namesort descending Description
layouter_element_info_alter Implements hook_element_info_alter().
layouter_menu Implements hook_menu().
layouter_permission Implements hook_permission().
layouter_text_format_pre_render Processes textarea element if it is allowed to enable Layouter.
layouter_theme Implements hook_theme().