Drupal,CCK - 删除非管理员的可拖动重新排序

时间:2010-06-23 19:01:26

标签: drupal cck drupal-theming

是否有一种干净的方法可以删除多值CCK字段上的可拖动选项?我假设我可以用CSS来设计它,但这似乎不是“正确”的方式。

理想情况下,除管理员外,任何用户都无法使用可拖动选项。

2 个答案:

答案 0 :(得分:1)

看起来tabledrag的东西正在cck主题函数中构建 - 例如theme_content_multiple_values它正在向表行添加一个'draggable'类,并调用 drupal_add_tabledrag在桌子上。

您应该能够在主题/模块(?)中覆盖它,并在添加拖动之前添加一个相当简单的开关来测试具有适当权限的用户。

答案 1 :(得分:0)

感谢@Andrew提示。以下是我最终提出的内容:

function stannes_content_multiple_values($element) {
    global $user;
    $field_name = $element['#field_name'];
    $field = content_fields($field_name);
    $output = '';

    if ($field['multiple'] >= 1) {
        $table_id = $element['#field_name'] .'_values';
        $order_class = $element['#field_name'] .'-delta-order';
        $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';

        $header = array(
            array( 'data' => t('!title: !required', array('!title' => $element['#title'], '!required' => $required)), 'colspan' => 2)
        );

        if ($user->uid == 1) {
            $header[] = t('Order');
        }

        $rows = array();

        // Sort items according to '_weight' (needed when the form comes back after
        // preview or failed validation)
        $items = array();
        foreach (element_children($element) as $key) {
            if ($key !== $element['#field_name'] .'_add_more') {
                $items[] = &$element[$key];
            }
        }
        usort($items, '_content_sort_items_value_helper');

        // Add the items as table rows.
        foreach ($items as $key => $item) {
            $item['_weight']['#attributes']['class'] = $order_class;
            $delta_element = drupal_render($item['_weight']);
            if ($user->uid == 1) {
                $cells = array(
                    array('data' => '', 'class' => 'content-multiple-drag'),
                    drupal_render($item),
                    array('data' => $delta_element, 'class' => 'delta-order'),
                );
            } else {
                $cells = array(
                    drupal_render($item)
                );
            }
            $rows[] = array(
                'data' => $cells,
                'class' => 'draggable',
            );
        }

        $output .= theme('table', $header, $rows, array('id' => $table_id, 'class' => 'content-multiple-table'));
        $output .= $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '';
        $output .= drupal_render($element[$element['#field_name'] .'_add_more']);

        if ($user->uid == 1) {
            drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class);
        }
    } else {
        foreach (element_children($element) as $key) {
            $output .= drupal_render($element[$key]);
        }
    }

    return $output;
}