You are here

function layouter_load_by_field in Layouter - WYSIWYG layout templates 7

Enables Layouter for given textarea field.

1 call to layouter_load_by_field()
layouter_text_format_pre_render in ./layouter.module
Processes textarea element if it is allowed to enable Layouter.

File

includes/layouter.inc, line 32
Functions for layout processing.

Code

function layouter_load_by_field($field, $format) {
  static $processed_ids = array();
  $cond1 = !isset($field['#id']) || isset($processed_ids[$field['#id']]) || $field['#id'] == 'edit-log';
  $cond2 = isset($field['#access']) && !$field['#access'];
  $cond3 = isset($field['#attributes']['disabled']) && $field['#attributes']['disabled'] == 'disabled';
  if ($cond1 || $cond2 || $cond3) {
    return $field;
  }
  $format_arr = FALSE;
  if (is_array($format)) {
    $format_arr = $format;
    $format = isset($format_arr['#value']) ? $format_arr['#value'] : $format_arr['#default_value'];
  }
  drupal_add_js(array(
    'layouter' => array(
      'default_formats' => array(
        $field['#id'] => $format,
      ),
    ),
  ), 'setting');
  if (!isset($processed_ids[$field['#id']])) {
    $processed_ids[$field['#id']] = array();
  }
  $textarea_id = $field['#id'];
  $class = 'layouter';
  $layouter_link_attrs = array(
    'attributes' => array(
      'id' => array(
        'layouter-' . $textarea_id,
      ),
      'class' => array(
        'layouter-link',
        'ctools-use-modal',
        $textarea_id,
      ),
      'title' => t('Click to select the text template with a simplified form of layout'),
    ),
  );
  $suffix = '<div class="layouter-link-wrapper">';
  $suffix .= l(t('Select the text template'), 'admin/layouter/' . $textarea_id, $layouter_link_attrs);
  $suffix .= '</div>';

  // Remember extra information and reuse it during "Preview".
  $processed_ids[$field['#id']]['suffix'] = $suffix;
  $processed_ids[$field['#id']]['class'][] = $class;
  $field['#suffix'] = empty($field['#suffix']) ? $suffix : $field['#suffix'] . $suffix;
  $field['#attributes']['class'][] = $class;
  return $field;
}