You are here

function crumbs_Admin_ElementObject_WeightsTabledrag::value_callback in Crumbs, the Breadcrumbs suite 7.2

Callback for $element['#value_callback']

Parameters

array $element:

array|bool $input:

array $form_state:

Return value

array

Overrides crumbs_Admin_ElementObject_Abstract::value_callback

File

lib/Admin/ElementObject/WeightsTabledrag.php, line 13

Class

crumbs_Admin_ElementObject_WeightsTabledrag

Code

function value_callback(&$element, $input = FALSE, $form_state = array()) {
  if ($input === FALSE) {
    return isset($element['#default_value']) ? $element['#default_value'] : array();
  }
  else {
    $weights = array();
    $i = 0;
    $section_key = NULL;
    foreach ($input as $row_key => $row_values) {
      if (substr($row_key, 0, 9) === 'sections.') {
        $section_key = substr($row_key, 9);
        if ($section_key === 'auto') {
          break;
        }
      }
      elseif (substr($row_key, 0, 6) === 'rules.') {
        $key = substr($row_key, 6);
        if ($section_key === 'enabled') {
          $weights[$key] = ++$i;
        }
        elseif ($section_key === 'disabled') {
          $weights[$key] = FALSE;
        }
      }
    }
    return $weights;
  }
}