سؤال

هل هناك طريقة نظيفة لإزالة خيار السحب على حقول CCK متعددة القيمة؟ أفترض أنه يمكنني تصميمه باستخدام CSS ، لكن هذا لا يبدو مثل الطريقة "الصحيحة" للقيام بذلك.

من الناحية المثالية ، لن يكون الخيار القابل للتسحب متاحًا لأي مستخدمين باستثناء المشرفين.

هل كانت مفيدة؟

المحلول 2

شكرا على النصيحة @أندرو. إليك ما انتهى بي الأمر إلى:

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;
}

نصائح أخرى

يبدو أن الأشياء tabledrag مبنية في وظائف موضوع CCK - على سبيل المثال theme_content_multiple_values إنها تضيف فئة "قابلة للسحب" إلى صفوف الجدول ، والاتصالdrupal_add_tabledrag على الطاولة.

يجب أن تكون قادرًا على تجاوز هذا في السمة/الوحدة النمطية (؟) وإضافة مفتاح بسيط إلى حد ما لاختبار المستخدمين بإذن مناسب قبل إضافة السحب.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top