You are here

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

Callback for $element['#value_callback']

Parameters

array $element:

bool $input:

array $form_state:

Return value

array|bool

Overrides crumbs_Admin_ElementObject_Abstract::value_callback

File

lib/Admin/ElementObject/WeightsTextual.php, line 14

Class

crumbs_Admin_ElementObject_WeightsTextual

Code

function value_callback(&$element, $input = FALSE, $form_state = array()) {
  if (FALSE === $input) {
    return isset($element['#default_value']) ? $element['#default_value'] : array();
  }

  /** @var crumbs_PluginSystem_PluginInfo $info */
  $info = $element['#crumbs_plugin_info'];
  $available_keys_meta = $info->availableKeysMeta;
  $weights = array();
  $weight = 0;
  foreach (explode("\n", $input['text']) as $line) {
    $line = trim($line);
    list($key, $title) = explode(' ', $line, 2) + array(
      NULL,
      NULL,
    );
    if (isset($available_keys_meta[$key])) {
      $weights[$key] = $weight;
      ++$weight;
    }
    elseif (preg_match('/^-/', $line)) {
      if ($weight !== FALSE) {
        $weight = FALSE;
      }
      else {
        break;
      }
    }
  }
  return $weights;
}