You are here

function layout_admin_region_list_form in Layout 7

Form callback to generate region list overview form.

See also

layout_admin_region_list_form_submit()

1 string reference to 'layout_admin_region_list_form'
layout_admin_region_list in ./layout.admin.regions.inc
Administration page for the region list.

File

./layout.admin.regions.inc, line 24
Responsive layout builder tool administration interface for regions.

Code

function layout_admin_region_list_form($form, $form_state, $regions) {
  $form = array();
  $form['regions'] = array(
    '#tree' => TRUE,
  );
  foreach ($regions as $region) {

    // Build friendly list of layouts this region is used in.
    $in_use_in_layouts = array_values(layout_get_layouts_using_region($region->name));
    $layout_count = count($in_use_in_layouts);
    if ($layout_count > 4) {

      // If over 4 layouts use this region, cut the list on the third and
      // mention the rest by number.
      $in_use_in_layouts = t('@list_of_layouts and @count more', array(
        '@list_of_layouts' => join(', ', array_slice($in_use_in_layouts, 0, 3)),
        '@count' => $layout_count - 3,
      ));
    }
    elseif ($layout_count == 0) {
      $in_use_in_layouts = t('- None -');
    }
    else {

      // Otherwise list all layouts.
      $in_use_in_layouts = check_plain(join(', ', $in_use_in_layouts));
    }
    $form['regions'][$region->name] = array(
      'admin_title' => array(
        '#type' => 'markup',
        '#markup' => check_plain($region->admin_title),
      ),
      'name' => array(
        '#type' => 'markup',
        '#markup' => check_plain($region->name),
      ),
      'in_use_in_layouts' => array(
        '#type' => 'markup',
        '#markup' => $in_use_in_layouts,
      ),
      'weight' => array(
        '#type' => 'weight',
        '#default_value' => $region->weight,
        '#delta' => count($regions),
        '#attributes' => array(
          'class' => array(
            'layout-region-weight',
          ),
        ),
      ),
      'default' => array(
        '#type' => 'checkbox',
        '#default_value' => !$region->custom,
      ),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save regions',
  );
  return $form;
}