You are here

function layouter_text_format_pre_render in Layouter - WYSIWYG layout templates 7

Processes textarea element if it is allowed to enable Layouter.

1 string reference to 'layouter_text_format_pre_render'
layouter_element_info_alter in ./layouter.module
Implements hook_element_info_alter().

File

./layouter.module, line 128
This module provide ability to add layout to text fields.

Code

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;
}