Перетаскиваемые строки в Drupal для формы администратора модуля - редактировать / удалять ссылки не видно - PullRequest
1 голос
/ 05 декабря 2010

У меня есть простой модуль, который я создаю с помощью перетаскиваемых строк, и он работает, за исключением того, что ссылки редактирования / удаления, которые у меня были для каждой строки ранее, теперь скрыты вместе с выбором веса (который, я знаю, должен быть скрыт) , Он помещает ссылки редактирования / удаления в тот же скрытый тд, что и вес. В моем коде чего-то не хватает, но я просто не вижу этого. Форма:

function contestwinners_admin_form() {
  $winners = _contestwinners_load_winners(NULL, TRUE);
  $path = drupal_get_path('module', 'contestwinners') .'/';
  $form = array();
  $form['#tree'] = TRUE;
  foreach ($winners as $winner) {
    $form['winners'][$winner['crid']]['#winner'] = $winner;

    $form['winners'][$winner['crid']]['edit'] = array(
      '#type' => 'image_button',
      '#title' => t('Edit winner'),
      '#src' => $path .'text-editor.png',
      '#submit' => array('contestwinners_admin_edit_button'),
      '#crid' => $winner['crid'],
    );
    $form['winners'][$winner['crid']]['delete'] = array(
      '#type' => 'image_button',
      '#title' => t('Delete winner'),
      '#src' => $path .'edit-delete.png',
      '#submit' => array('contestwinners_admin_delete_button'),
      '#crid' => $winner['crid'],
    );

    // the "weight" field will be manipulated by the drag and drop table
    $form['winners'][$winner['crid']]['weight'] = array(
       '#type' => 'weight',
       '#delta' => 10,
       '#default_value' => $winner['weight'],
       '#attributes' => array('class' => 'weight'),
       );    

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save Changes'),
        );

  }
  return $form;
}

Тематическая функция:

function theme_contestwinners_admin_form(&$form) {

  $headers = array(t('Name'), t('Description'), t('Actions'));

  $rows = array();

  if (!empty($form['winners'])) {
    foreach (element_children($form['winners']) as $crid) {
      $row = array();
      $winner = $form['winners'][$crid]['#winner'];
      $row[] = check_plain($winner['title']);
      $row[] = check_plain($winner['description']);
      $row[] = drupal_render($form['winners'][$crid]);

        // Add the weight field to the row
        // the Javascript to make our table drag and drop will end up hiding this cell
        $row[] = drupal_render($form['winners']['weight']);

        //Add the row to the array of rows
        $rows[] = array('data' => $row, 'class'=>'draggable');

    }
  }

  //print_r($rows);

  $link = l(t('Create a new winner'), 'admin/settings/contestwinners/add');

    $table_id = 'winners';

    // this function is what brings in the javascript to make our table drag-and-droppable
    drupal_add_tabledrag($table_id, 'order', 'sibling', 'weight');    

  $row = array();
  if (empty($rows)) {
    $row[] = array(
      'data' => t('No contest winners have been added yet. !url.', array('!url' => $link)),
      'colspan' => 4,
      'class'=>'draggable',
    );
  }else{
    $row[] = array(
      'data' => t('!url.', array('!url' => $link)),
      'colspan' => 4,
      'class'=>'draggable',
    );
  }

  $rows[] = $row;



    // over-write the 'my_items' form element with the markup generated from our table
    $form['winners'] = array(
        '#type' => 'markup',
        '#value' => theme('table', $headers, $rows, array('id' => $table_id)),
        '#weight' => '1',
        );


 // $output .= theme('table', $headers, $form);
  $output .= drupal_render($form);
  return $output;
}

Изменить до исходного поста ниже:

Я вроде понял это сейчас. Я помещаю их в отдельные тд, пока не пойму, как это сделать другим способом. В функцию theme_contestwinners_admin_form () я положил

function theme_contestwinners_admin_form(&$form) {
  $headers = array(t('Name'), t('Description'), t('Edit'), t('Delete'), t('Weight'));
  $rows = array();
  if (!empty($form['winners'])) {
    foreach (element_children($form['winners']) as $crid) {
      $row = array();
      $winner = $form['winners'][$crid]['#winner'];
      $row[] = check_plain($winner['title']);
      $row[] = check_plain($winner['description']);
      $row[] = drupal_render($form['winners'][$crid]['edit']);
      $row[] = drupal_render($form['winners'][$crid]['delete']);
      // Add the weight field to the row
      // the Javascript to make our table drag and drop will end up hiding this cell
      $row[] = drupal_render($form['winners'][$crid]['weight']);
        //Add the row to the array of rows
        $rows[] = array('data' => $row, 'class'=>'draggable');
    }
  }

  $link = l(t('Create a new winner'), 'admin/settings/contestwinners/add');

    $table_id = 'winners';

    // this function is what brings in the javascript to make our table drag-and-droppable
    drupal_add_tabledrag($table_id, 'order', 'sibling', 'weight');    

  $row = array();
  if (empty($rows)) {
    $row[] = array(
      'data' => t('No contest winners have been added yet. !url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }else{
    $row[] = array(
      'data' => t('!url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }

  $rows[] = $row;
    // over-write the 'my_items' form element with the markup generated from our table
    $form['winners'] = array(
        '#type' => 'markup',
        '#value' => theme('table', $headers, $rows, array('id' => $table_id)),
        '#weight' => '1',
        );

    $output = '';
    $output .= drupal_render($form);
    return $output;
}

1 Ответ

0 голосов
/ 15 февраля 2011

Я вроде понял это сейчас. Я помещаю их в отдельные тд, пока не пойму, как это сделать другим способом. В функцию theme_contestwinners_admin_form () я положил

function theme_contestwinners_admin_form(&$form) {
  $headers = array(t('Name'), t('Description'), t('Edit'), t('Delete'), t('Weight'));
  $rows = array();
  if (!empty($form['winners'])) {
    foreach (element_children($form['winners']) as $crid) {
      $row = array();
      $winner = $form['winners'][$crid]['#winner'];
      $row[] = check_plain($winner['title']);
      $row[] = check_plain($winner['description']);
      $row[] = drupal_render($form['winners'][$crid]['edit']);
      $row[] = drupal_render($form['winners'][$crid]['delete']);
      // Add the weight field to the row
      // the Javascript to make our table drag and drop will end up hiding this cell
      $row[] = drupal_render($form['winners'][$crid]['weight']);
        //Add the row to the array of rows
        $rows[] = array('data' => $row, 'class'=>'draggable');
    }
  }

  $link = l(t('Create a new winner'), 'admin/settings/contestwinners/add');

    $table_id = 'winners';

    // this function is what brings in the javascript to make our table drag-and-droppable
    drupal_add_tabledrag($table_id, 'order', 'sibling', 'weight');    

  $row = array();
  if (empty($rows)) {
    $row[] = array(
      'data' => t('No contest winners have been added yet. !url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }else{
    $row[] = array(
      'data' => t('!url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }

  $rows[] = $row;
    // over-write the 'my_items' form element with the markup generated from our table
    $form['winners'] = array(
        '#type' => 'markup',
        '#value' => theme('table', $headers, $rows, array('id' => $table_id)),
        '#weight' => '1',
        );

    $output = '';
    $output .= drupal_render($form);
    return $output;
}
...