You are here

public static function RulesUICategory::getOptions in Rules 7.2

Returns an array of options to use with a select.

Returns an array of options to use with a selectfor the items specified in the given hook.

Parameters

string $item_type: The item type to get options for. One of 'data', 'event', 'condition' and 'action'.

array|null $items: (optional) An array of items to restrict the options to.

Return value

array An array of options.

1 call to RulesUICategory::getOptions()
RulesPluginUI::getOptions in ui/ui.core.inc

File

ui/ui.core.inc, line 1311
Contains core Rules UI functions.

Class

RulesUICategory
Class holding category related methods.

Code

public static function getOptions($item_type, $items = NULL) {
  $sorted_data = array();
  $ungrouped = array();
  $data = $items ? $items : rules_fetch_data($item_type . '_info');
  foreach ($data as $name => $info) {

    // Verify the current user has access to use it.
    if (!user_access('bypass rules access') && !empty($info['access callback']) && !call_user_func($info['access callback'], $item_type, $name)) {
      continue;
    }
    if ($group = RulesUICategory::getItemGroup($info)) {
      $sorted_data[drupal_ucfirst($group)][$name] = drupal_ucfirst($info['label']);
    }
    else {
      $ungrouped[$name] = drupal_ucfirst($info['label']);
    }
  }
  asort($ungrouped);
  foreach ($sorted_data as $key => $choices) {
    asort($choices);
    $sorted_data[$key] = $choices;
  }

  // Sort the grouped data by category weights, defaulting to weight 0 for
  // groups without a respective category.
  $sorted_groups = array();
  foreach (array_keys($sorted_data) as $label) {
    $sorted_groups[$label] = array(
      'weight' => 0,
      'label' => $label,
    );
  }

  // Add in category weights.
  foreach (RulesUICategory::getInfo() as $info) {
    if (isset($sorted_groups[$info['label']])) {
      $sorted_groups[$info['label']] = $info;
    }
  }
  uasort($sorted_groups, '_rules_ui_sort_categories');

  // Now replace weights with group content.
  foreach ($sorted_groups as $group => $weight) {
    $sorted_groups[$group] = $sorted_data[$group];
  }
  return $ungrouped + $sorted_groups;
}