You are here

function _rules_filter_rules_table_components in Rules filter 7

Returns Tabs and Rules table.

Parameters

bool $is_rules_page: TRUE if it is Rules page.

Return value

array Contains: -table: rules table. -tabs: tabs.

1 call to _rules_filter_rules_table_components()
rules_filter_preprocess_rules_filter_rules_form in theme/theme.inc
Implements template_preprocess().

File

includes/pages.inc, line 78
Page elements for the module.

Code

function _rules_filter_rules_table_components($is_rules_page) {

  // Prepare conditions and options for Rules and Components pages.
  if ($is_rules_page) {
    $conditions = array(
      'plugin' => 'reaction rule',
    );
    $options = array(
      'show plugin' => FALSE,
    );
  }
  else {
    $conditions = array(
      'plugin' => array_keys(rules_filter_array(rules_fetch_data('plugin_info'), 'component', TRUE)),
    );
    $options = array(
      'hide status op' => TRUE,
    );
  }

  // Get Rules or Components table.
  $rules_table = rules_ui()
    ->overviewTable($conditions, $options);

  // Wraps header labels to make them sortable.
  $rules_table['#header'][0] = '<div class="sort" data-sort="rules-element-content">' . $rules_table['#header'][0] . '</div>';
  $rules_table['#header'][1] = '<div class="sort" data-sort="search-field">' . $rules_table['#header'][1] . '</div>';
  $rules_table['#header'][3] = '<div class="sort" data-sort="rule-status">' . $rules_table['#header'][3] . '</div>';

  // Adds class if table is empty.
  if (empty($rules_table['#rows'])) {
    $rules_table['#attributes']['class'][] = 'empty';
  }

  // Default tabs.
  $default_tabs = array(
    _rules_filter_tabs_link(t('All'), 'all'),
    _rules_filter_tabs_link(t('No tags'), 'no-tags'),
  );
  $tabs = [];

  // Prepare tabs and add necessary classes to table rows.
  foreach ($rules_table['#rows'] as &$row) {

    // Adds invisible rule label for sorting by rules name.
    $invisible_label = array(
      'invisible_label' => array(
        '#markup' => $row[0]['data']['label']['#title'],
        '#prefix' => '<div class="element-invisible">',
        '#suffix' => '</div>',
      ),
    );
    $row[0]['data'] = $invisible_label + $row[0]['data'];

    // Adds invisible rule status for sorting by rules status.
    $row[2]['data'] = array(
      'invisible_status' => array(
        '#markup' => $row[2]['data']['#status'],
        '#prefix' => '<div class="element-invisible">',
        '#suffix' => '</div>',
      ),
      'status' => $row[2]['data'],
      '#prefix' => '<span class="rule-status">',
      '#suffix' => '</span>',
    );

    // Wrap Event column to span with class for search.
    $row[1] = '<span class="search-field">' . $row[1] . '</span>';

    // Check if rule enabled or disabled (only for rules page).
    if ($is_rules_page) {
      $enabled_class = strpos($row[4], 'enable') === FALSE && strpos($row[5], 'enable') === FALSE ? 'enabled' : 'disabled';
    }

    // Replace operation links to dropdowns menu if ctools module exists.
    if (module_exists('ctools')) {
      $operations = array();
      $count = count($row);
      for ($ind = 3; $ind < $count; $ind++) {
        if (!empty($row[$ind])) {
          $operations[] = $row[$ind];
        }
        unset($row[$ind]);
      }
      $row[3] = _rules_filter_operations_dropdown($operations);
    }

    // Converts rows format.
    $row = array(
      'data' => $row,
    );
    $classes = array(
      'all',
    );
    if (!empty($row['data'][0]['data']['description']['tags']['tags']['#markup'])) {
      $tags = explode(', ', $row['data'][0]['data']['description']['tags']['tags']['#markup']);
      foreach ($tags as $tag) {

        // Convert Tag to class name.
        $class = preg_replace("![^a-z0-9]+!i", "-", strtolower($tag));

        // Generate hash if class is cyrillic or any problems with converting.
        if ($class == '-') {
          $class = substr(md5($class), 0, 8);
        }
        $classes[] = $class;

        // Prepare links for tabs.
        $tabs[$tag] = _rules_filter_tabs_link($tag, $class);
      }
    }
    else {
      $classes[] = 'no-tags';
    }

    // Adds enabled/disabled class if its rules page.
    if ($is_rules_page) {
      $classes[] = $enabled_class;
    }
    $row['class'] = $classes;
  }

  // Attach css and js files.
  _rules_filter_form_attach_styles($rules_table);

  // Sort tabs and add default tabs to the top.
  ksort($tabs);
  $tabs = array_merge($default_tabs, $tabs);
  return array(
    'table' => $rules_table,
    'tabs' => array(
      '#markup' => theme('item_list', array(
        'items' => $tabs,
      )),
    ),
  );
}