1 layout.flexible.inc layout_flexible_template_get_last_region_number(LayoutFlexibleTemplate $flexible_template, $form_state = NULL)

Returns the last number of all regions named "Region X" where X is a number.

File

core/modules/layout/layout.flexible.inc, line 578
Provides configurable (flexible) layout templates.

Code

function layout_flexible_template_get_last_region_number(LayoutFlexibleTemplate $flexible_template, $form_state = NULL) {
  $last = 0;
  if ($form_state) {
    $region_names = array_filter($form_state['values']['region_names']);
    $last = $form_state['last_region_number'];
  }
  else {
    $region_names = array();
    foreach ($flexible_template->rows as $row) {
      foreach ($row['region_names'] as $name) {
        $region_names[] = $name;
      }
    }
  }

  foreach ($region_names as $region) {
    $str = explode('Region ', $region);
    if (!empty($str[1]) && is_numeric($str[1]) && $str[1] > $last) {
      $last = $str[1];
    }
  }

  return $last;
}