drupal admin.inc,循环list_modules作为表单设置

时间:2012-06-29 07:47:02

标签: arrays forms drupal loops

我需要循环这个

的值
$blocks = array();

$blocks['list_modules']

用这个:

$form['advanced']['custom_acc'] = array(
    '#type' => 'select',
    '#title' => t('module title'),
    '#options' => array(
      0 => t('No control'),
      1 => t('Controlled'),
      ),
  );

所以它应该变成类似这个

        while (list(, $value) = each($blocks)) {
        echo "

    $form['advanced']['custom_->blocks array value'] = array(
        '#type' => 'select',
        '#title' => t('->blocks array value'),
        '#options' => array(
          0 => t('No control'),
          1 => t('Controlled'),
          ),
      );
  ";
}

但当然这不起作用,有什么想法吗?我想我必须使用foreach,我希望你能看到我想要实现的目标,

提前感谢!

1 个答案:

答案 0 :(得分:0)

自己修理:)

    $blocks = array();
$blocks = module_list();

foreach ($blocks as $key => $title) {

$form['advanced'][$title] = array(
    '#type' => 'select',
    '#title' => t($title),
    '#options' => array(
      0 => t('No control'),
      1 => t('Controlled'),
      ),
  );
}