You are here

function panels_flexible_add_item_form in Panels 7.3

Same name and namespace in other branches
  1. 6.3 plugins/layouts/flexible/flexible.inc \panels_flexible_add_item_form()

Form to add a row, column or region to a flexible layout.

1 string reference to 'panels_flexible_add_item_form'
panels_ajax_flexible_edit_add in plugins/layouts/flexible/flexible.inc
AJAX responder to add a new row, column or region to a flexible layout.

File

plugins/layouts/flexible/flexible.inc, line 1450
Flexible layout plugin.

Code

function panels_flexible_add_item_form($form, &$form_state) {
  $display =& $form_state['display'];
  $item =& $form_state['item'];
  $parent =& $form_state['parent'];
  $settings =& $form_state['settings'];
  $location =& $form_state['location'];
  $id =& $form_state['id'];
  if ($item['type'] == 'region') {
    $form['title'] = array(
      '#title' => t('Region title'),
      '#type' => 'textfield',
      '#default_value' => $item['title'],
      '#required' => TRUE,
    );
  }
  $form['class'] = array(
    '#title' => t('CSS Class'),
    '#type' => 'textfield',
    '#default_value' => isset($item['class']) ? $item['class'] : '',
    '#description' => t('Enter a CSS class that will be used. This can be used to apply automatic styling from your theme, for example.'),
  );
  if ($item['type'] != 'row') {

    // If there is a 'fixed' type on the side we're adding to, then this
    // must also be fixed. Otherwise it can be either and should default to
    // fluid.
    $restrict = FALSE;
    if (!empty($parent['children'])) {
      if ($location == 'left') {
        $sibling = reset($parent['children']);
      }
      else {
        $sibling = end($parent['children']);
      }
      if ($settings['items'][$sibling]['width_type'] == 'px') {
        $restrict = TRUE;
        $item['width_type'] = 'px';
      }
    }
    $form['width_type'] = array(
      '#type' => 'select',
      '#title' => t('Width'),
      '#default_value' => $item['width_type'],
      '#options' => array(
        '%' => t('Fluid'),
        'px' => t('Fixed'),
      ),
      '#disabled' => $restrict,
    );
    if ($restrict) {

      // This forces the value because disabled items don't always send
      // their data back.
      $form['width_type']['#value'] = $item['width_type'];
      $form['width_type']['#description'] = t('Items cannot be set to fluid if there are fixed items already on that side.');
    }
  }
  else {
    $form['contains'] = array(
      '#type' => 'select',
      '#title' => t('Contains'),
      '#default_value' => $item['contains'],
      '#options' => array(
        'region' => t('Regions'),
        'column' => t('Columns'),
      ),
    );
  }
  $form['hide_empty'] = array(
    '#title' => t('Hide element if empty'),
    '#type' => 'checkbox',
    '#default_value' => 0,
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}