You are here

function theme_themekey_abstract_rule_chain_form in ThemeKey 7.3

3 calls to theme_themekey_abstract_rule_chain_form()
theme_themekey_css_rule_chain_form in themekey_css/themekey_css_admin.inc
Themes themekey_css_rule_chain_form() and adds drag'n'drop features.
theme_themekey_redirect_rule_chain_form in themekey_redirect/themekey_redirect_admin.inc
Themes themekey_redirect_rule_chain_form() and adds drag'n'drop features.
theme_themekey_rule_chain_form in ./themekey_admin.inc
Themes themekey_rule_chain_form() and adds drag'n'drop features.

File

./themekey_admin.inc, line 670

Code

function theme_themekey_abstract_rule_chain_form($variables, $options) {
  $form = $variables['form'];
  themekey_admin_theme_warning();
  $output = '';
  $rows = array();
  $num_childs = array();
  if (!empty($form['old_items'])) {
    $parents_disabled = array();
    $attributes = variable_get('themekey_attributes', array());
    foreach ($form['old_items'] as $key => $item) {
      if (is_numeric($key) && !empty($item['property'])) {
        themekey_deprected_property_warning($item['property']['#value']);
        $parents_disabled[$key] = FALSE;
        if (!empty($parents_disabled[$item['parent']['#value']])) {
          $form['old_items'][$key]['enabled']['#value'] = 0;
        }
        if (!$form['old_items'][$key]['enabled']['#value']) {
          $parents_disabled[$key] = TRUE;
        }
        elseif (!empty($item['parent']['#value'])) {
          $num_childs[$item['parent']['#value']] = empty($num_childs[$item['parent']['#value']]) ? 1 : $num_childs[$item['parent']['#value']] + 1;
        }
      }
    }
    foreach ($form['old_items'] as $key => $item) {
      if (is_numeric($key) && !empty($item['property'])) {
        $row = isset($form['old_items'][$key]['#attributes']) && is_array($form['old_items'][$key]['#attributes']) ? $form['old_items'][$key]['#attributes'] : array();

        // Add special classes to be used for tabledrag.js.
        $form['old_items'][$key]['id']['#attributes']['class'] = array(
          'themekey-property-id',
        );
        $form['old_items'][$key]['parent']['#attributes']['class'] = array(
          'themekey-property-parent',
        );
        $form['old_items'][$key]['weight']['#attributes']['class'] = array(
          'themekey-property-weight',
        );

        // Add special classes to be used for themekey-properties.js.
        $form['old_items'][$key]['property']['#attributes']['class'] = array(
          'themekey-property-property themekey-fadeable',
        );
        $form['old_items'][$key]['wildcard']['#attributes']['class'] = array(
          'themekey-property-wildcard themekey-fadeable',
        );
        $form['old_items'][$key]['operator']['#attributes']['class'] = array(
          'themekey-fadeable',
        );
        $form['old_items'][$key]['value']['#attributes']['class'] = array(
          'themekey-fadeable',
        );
        $form['old_items'][$key]['enabled']['#attributes']['class'] = array(
          'themekey-property-enabled',
        );
        $form['old_items'][$key]['theme']['#attributes']['class'] = array(
          'themekey-property-theme themekey-fadeable',
        );

        // Add special classes to [old_items] additional columns.
        if (isset($options['additional_fields'])) {
          foreach ($options['additional_fields'] as $field_name) {
            $form['old_items'][$key][$field_name]['#attributes']['class'] = array(
              drupal_clean_css_identifier("themekey-property-{$field_name}"),
            );
          }
        }
        if (isset($form['old_items'][$key]['append_path'])) {

          // Special element of ThemeKey Redirect. See themekey_redirect_rule_chain_form().
          $form['old_items'][$key]['append_path']['#attributes']['class'] = array(
            'themekey-property-append-path themekey-fadeable',
          );
        }

        // form items of type markup don't have attributes
        $form['old_items'][$key]['delete']['#markup'] = str_replace('<a', '<a class="themekey-rule-delete-link"', $form['old_items'][$key]['delete']['#markup']);
        if ('drupal:path:wildcard' != $item['property']['#value']) {
          $form['old_items'][$key]['wildcard']['#attributes']['style'] = 'display: none';
        }
        if (!empty($num_childs[$key])) {
          $form['old_items'][$key]['theme']['#attributes']['style'] = 'display: none';
          if (isset($form['old_items'][$key]['append_path'])) {
            $form['old_items'][$key]['append_path']['#attributes']['style'] = 'display: none';
          }

          // form items of type markup don't have attributes
          $form['old_items'][$key]['delete']['#markup'] = str_replace('<a', '<a style="display: none"', $form['old_items'][$key]['delete']['#markup']);
        }
        if (!empty($parents_disabled[$item['parent']['#value']])) {
          $form['old_items'][$key]['enabled']['#attributes']['style'] = 'display: none';
          $form['old_items'][$key]['enabled']['#default_value'] = 0;
        }
        $elements = array();
        $description = htmlentities(strip_tags($attributes[$form['old_items'][$key]['property']['#default_value']]['description']));
        $description = str_replace('\'', '', $description);
        $elements[] = array(
          'data' => theme('indentation', array(
            'size' => $form['old_items'][$key]['depth']['#value'],
          )) . drupal_render($form['old_items'][$key]['id']) . drupal_render($form['old_items'][$key]['property']) . drupal_render($form['old_items'][$key]['wildcard']) . drupal_render($form['old_items'][$key]['operator']) . drupal_render($form['old_items'][$key]['value']) . '<a name="anchor-' . $key . '" href="#anchor-' . $key . '" id="' . drupal_clean_css_identifier('edit-old-items-' . $key . '-value-help') . '" class="themekey-fadeable" title="' . $description . '" onClick="alert(\'' . $description . '\')">?</a>',
          'class' => array(
            'themekey-properties-row',
          ),
        );
        $elements[] = array(
          'data' => drupal_render($form['old_items'][$key]['theme']) . (isset($form['old_items'][$key]['append_path']) ? drupal_render($form['old_items'][$key]['append_path']) : ''),
        );

        // Extend table with [old_items] additional columns.
        // It would be logical to place addition columns between 'theme'
        // and 'enabled' columns.
        if (isset($options['additional_fields'])) {
          foreach ($options['additional_fields'] as $field_name) {
            $elements[] = array(
              'data' => drupal_render($form['old_items'][$key][$field_name]),
            );
          }
        }
        $elements[] = array(
          'data' => drupal_render($form['old_items'][$key]['enabled']),
        );
        $elements[] = array(
          'data' => drupal_render($form['old_items'][$key]['delete']),
        );
        $elements[] = array(
          'data' => drupal_render($form['old_items'][$key]['parent']),
        );
        $elements[] = array(
          'data' => drupal_render($form['old_items'][$key]['weight']),
        );
        $page_cache = $attributes[$form['old_items'][$key]['property']['#default_value']]['page cache'];
        drupal_alter('themekey_page_cache_support', $page_cache, $key, $form['#form_id']);
        if ($form['old_items'][$key]['enabled']['#value']) {
          themekey_page_cache_warning($page_cache);
        }
        $elements[] = array(
          'data' => '<div id="' . drupal_clean_css_identifier('edit-old-items-' . $key . '-page-cache-icon') . '">' . theme('themekey_page_cache_icon', array(
            'page_cache_support' => $page_cache,
          )) . '</div>',
        );
        $row['class'][] = 'draggable';
        if (!$form['old_items'][$key]['enabled']['#value']) {
          $row['class'][] = 'themekey-fade-out';
        }
        if (!$form['old_items'][$key]['parent']['#value']) {
          $row['class'][] = 'themekey-top-level';
        }
        $row['id'] = 'themekey-properties-row-' . $key;
        $row['data'] = $elements;
        $rows[] = $row;
      }
    }
  }
  if (!empty($rows)) {
    if (empty($form['pager']['#value'])) {
      drupal_add_tabledrag('themekey-properties', 'match', 'parent', 'themekey-property-parent', 'themekey-property-parent', 'themekey-property-id', TRUE);
      drupal_add_tabledrag('themekey-properties', 'order', 'sibling', 'themekey-property-weight');
    }
    $output .= theme('table', array(
      'header' => $options['header'],
      'rows' => $rows,
      'attributes' => array(
        'id' => 'themekey-properties',
      ),
    ));
    foreach ($num_childs as $parent => $num) {
      $output .= '<input id="themekey-num-childs-' . $parent . '" type="hidden" value="' . $num . '"></input>';
    }
  }
  $rows = array();
  if (!empty($form['new_item'])) {
    if (isset($form['new_item']['property'])) {
      $row = isset($form['new_item']['#attributes']) && is_array($form['new_item']['#attributes']) ? $form['new_item']['#attributes'] : array();

      // Add special classes to be used for themekey-properties.js.
      $form['new_item']['property']['#attributes']['class'] = array(
        'themekey-property-property',
      );
      $form['new_item']['wildcard']['#attributes']['class'] = array(
        'themekey-property-wildcard',
      );
      if ('drupal:path:wildcard' != $form['new_item']['property']['#value']) {
        $form['new_item']['wildcard']['#attributes']['style'] = 'display: none';
      }

      // Add special classes to [new_item] additional columns.
      if (isset($options['additional_fields'])) {
        foreach ($options['additional_fields'] as $field_name) {
          $form['new_item'][$field_name]['#attributes']['class'] = array(
            drupal_clean_css_identifier("themekey-property-{$field_name}"),
          );
        }
      }
      $elements = array();
      $elements[] = t('New Rule:');
      $elements[] = array(
        'data' => drupal_render($form['new_item']['property']) . drupal_render($form['new_item']['wildcard']) . drupal_render($form['new_item']['operator']) . drupal_render($form['new_item']['value']),
        'class' => array(
          'themekey-properties-row',
        ),
      );
      $elements[] = array(
        'data' => drupal_render($form['new_item']['theme']) . (isset($form['new_item']['append_path']) ? drupal_render($form['new_item']['append_path']) : ''),
      );

      // Extend table with [new_item] additional columns.
      // It would be logical to place addition columns between 'theme'
      // and 'enabled' columns.
      if (isset($options['additional_fields'])) {
        foreach ($options['additional_fields'] as $field_name) {
          $elements[] = array(
            'data' => drupal_render($form['new_item'][$field_name]),
          );
        }
      }
      $elements[] = array(
        'data' => drupal_render($form['new_item']['enabled']),
      );
      $row['data'] = $elements;
      $rows[] = $row;
    }
  }
  if (!empty($rows)) {

    // Remove 'Operation', 'Parent', 'Weight' and 'Page Cache' from header array
    // for 'new_item' table.
    $header = $options['header'];
    array_unshift($header, '');
    foreach ($header as $key => $header_label) {
      if (in_array($header_label, array(
        t('Operation'),
        t('Parent'),
        t('Weight'),
        t('Page<br />Cache'),
      ))) {
        unset($header[$key]);
      }
    }
    $output .= '<a name="themekey_new_rule"></a>';
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'id' => 'themekey-new-item',
      ),
    ));
  }
  $output .= drupal_render_children($form);
  drupal_add_css(drupal_get_path('module', 'themekey') . '/themekey_rule_chain.admin.css');
  drupal_add_js(drupal_get_path('module', 'themekey') . '/themekey_rule_chain.admin.js');
  return $output;
}