如何以与块管理页面相同的方式创建包含部分的拖放 table?
How to create a drag and drop table with sections in same way as block admin page?
如何制作具有多个部分且支持拖放的 drupal table?
应该类似于drupal块管理页面:
.
我只在部分找到了有关如何执行此操作的示例。
有一篇不错的文章,您可能会在其中获得 answer,但您可能会发现以下指南更有用。
- 您可以创建具有改变体重能力的 table。这是构造函数的示例:
function mymodule_form_weights() {
$data = array(
array('id' => 1, 'title' => 'Lorem ipsum dolor sit amet', 'active' => 0, 'weight' => -10),
array('id' => 2, 'title' => 'Consectetuer adipiscing elit', 'active' => 1, 'weight' => -7),
array('id' => 3, 'title' => 'Ut wisi enim ad minim veniam', 'active' => 1, 'weight' => 0),
array('id' => 4, 'title' => 'Quis nostrud exerci tation', 'active' => 0, 'weight' => 5),
array('id' => 5, 'title' => 'Ullamcorper suscipit lobortis', 'active' => 0, 'weight' => 3),
);
$form['#tree'] = true;
foreach($data as $row) {
$form['table'][$row['id']]['title'] = array(
'#value' => $row['title'],
);
$form['table'][$row['id']]['active'] = array(
'#value' => $row['active'] ? 'yes' : 'no',
);
$form['table'][$row['id']]['weight'] = array(
'#type' => 'weight',
'#default_value' => $row['weight'],
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'save',
);
return $form;
}
- 主题化
function theme_mymodule_form_weights($form) {
$rows = array();
foreach(element_children($form['table']) as $id) {
$form['table'][$id]['weight']['#attributes'] = array('class' => 'weight');
$rows[$id]['class'] = 'draggable';
foreach(element_children($form['table'][$id]) as $name) {
$rows[$id]['data'][] = drupal_render($form['table'][$id][$name]);
}
}
drupal_add_tabledrag('weights-form', 'order', 'sibling', 'weight');
$output = theme('table', array('Title', 'Active', 'Weight'), $rows, array('id' => 'weights-form'));
$output. = drupal_render($form);
return $output;
}
3. hook_theme()
function mymodule_theme() {
return array(
'mymodule_form_weights' => array('arguments' => array('form' => null)),
);
}
不要忘记它是 php,而不是代码片段中的 js。
如何制作具有多个部分且支持拖放的 drupal table?
应该类似于drupal块管理页面:
我只在部分找到了有关如何执行此操作的示例。
有一篇不错的文章,您可能会在其中获得 answer,但您可能会发现以下指南更有用。
- 您可以创建具有改变体重能力的 table。这是构造函数的示例:
function mymodule_form_weights() {
$data = array(
array('id' => 1, 'title' => 'Lorem ipsum dolor sit amet', 'active' => 0, 'weight' => -10),
array('id' => 2, 'title' => 'Consectetuer adipiscing elit', 'active' => 1, 'weight' => -7),
array('id' => 3, 'title' => 'Ut wisi enim ad minim veniam', 'active' => 1, 'weight' => 0),
array('id' => 4, 'title' => 'Quis nostrud exerci tation', 'active' => 0, 'weight' => 5),
array('id' => 5, 'title' => 'Ullamcorper suscipit lobortis', 'active' => 0, 'weight' => 3),
);
$form['#tree'] = true;
foreach($data as $row) {
$form['table'][$row['id']]['title'] = array(
'#value' => $row['title'],
);
$form['table'][$row['id']]['active'] = array(
'#value' => $row['active'] ? 'yes' : 'no',
);
$form['table'][$row['id']]['weight'] = array(
'#type' => 'weight',
'#default_value' => $row['weight'],
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'save',
);
return $form;
}
- 主题化
function theme_mymodule_form_weights($form) {
$rows = array();
foreach(element_children($form['table']) as $id) {
$form['table'][$id]['weight']['#attributes'] = array('class' => 'weight');
$rows[$id]['class'] = 'draggable';
foreach(element_children($form['table'][$id]) as $name) {
$rows[$id]['data'][] = drupal_render($form['table'][$id][$name]);
}
}
drupal_add_tabledrag('weights-form', 'order', 'sibling', 'weight');
$output = theme('table', array('Title', 'Active', 'Weight'), $rows, array('id' => 'weights-form'));
$output. = drupal_render($form);
return $output;
}
function mymodule_theme() {
return array(
'mymodule_form_weights' => array('arguments' => array('form' => null)),
);
}
不要忘记它是 php,而不是代码片段中的 js。