You are here

protected function crumbs_Admin_ElementObject_WeightsTextual::getDefaultText in Crumbs, the Breadcrumbs suite 7.2

Get the text for the textarea

Parameters

array $element:

Return value

string

1 call to crumbs_Admin_ElementObject_WeightsTextual::getDefaultText()
crumbs_Admin_ElementObject_WeightsTextual::process in lib/Admin/ElementObject/WeightsTextual.php
Callback for $element['#process'] Create a big textarea.

File

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

Class

crumbs_Admin_ElementObject_WeightsTextual

Code

protected function getDefaultText($element) {
  $available_keys = $element['#crumbs_plugin_info']->availableKeysMeta;
  $weights = $element['#value'];
  $default_weights = $element['#crumbs_plugin_info']->defaultWeights;
  $key_lengths = array();
  foreach ($available_keys as $key => $title) {
    $key_lengths[] = strlen($key);
  }
  $ideal_length = $this
    ->findIdealLength($key_lengths);
  $key_lines = array();
  foreach ($available_keys as $key => $meta) {
    $string = $key;
    $desc = $meta->descriptions;
    if (!empty($desc[0])) {
      $title = $desc[0];
      if (strlen($string) < $ideal_length) {
        $string .= str_repeat(' ', $ideal_length - strlen($string));
      }
      $string .= ' - ' . $title;
    }
    $key_lines[$key] = $string;
  }
  $lines = array(
    'inherit' => $key_lines,
    'disabled_by_default' => array(),
    'enabled' => array(),
    'disabled' => array(),
  );
  foreach ($weights as $key => $weight) {
    $section = $weight === FALSE ? 'disabled' : 'enabled';
    $string = $key;
    if (isset($key_lines[$key])) {
      $string = $key_lines[$key];
    }
    else {
      if ($key !== '*') {

        // an orphan setting.
        if (strlen($string) < $ideal_length) {
          $string .= str_repeat(' ', $ideal_length - strlen($string));
        }
        $string .= '   (orphan rule)';
      }
    }
    $lines[$section][$key] = $string;
    unset($lines['inherit'][$key]);
  }
  foreach ($default_weights as $key => $default_weight) {
    if (isset($lines['inherit'][$key]) && FALSE === $default_weight) {
      $lines['disabled_by_default'][$key] = $lines['inherit'][$key];
      unset($lines['inherit'][$key]);
    }
  }
  ksort($lines['inherit']);
  $module = FALSE;
  foreach ($lines['inherit'] as $key => $line) {
    if (isset($prev) && $prev === '' && $line === '') {
      unset($lines['inherit'][$key]);
    }
    $pieces = explode('.', $key);
    if ($module !== $pieces[0]) {
      if (FALSE !== $module) {

        // Add in a blank line.
        $lines['inherit'][$key] = "\n" . $line;
      }
      $module = $pieces[0];
    }
    $prev = $line;
  }
  return "\n\n" . implode("\n", $lines['enabled']) . "\n\n\n---- disabled ----\n\n" . implode("\n", $lines['disabled']) . "\n\n\n---- disabled by default ----\n\n" . implode("\n", $lines['disabled_by_default']) . "\n\n\n---- inherit ----\n\n" . implode("\n", $lines['inherit']) . "\n\n";
}