私はDrupalモジュールを構築して、管理フォームを使用してアイコンを特定のページに結びつけています。特定のディレクトリに配置された各イメージは、すべてのプライマリリンクタイトルを示すセレクトボックスの横に出力する必要があります。Drupal Form API - foreachループを使用してフォームを構築する
foreach
ループを使用してフォームを作成しましたが、_submit関数でdpm($form);
を使用して出力をチェックすると、各画像ページの#valueは常に最後の画像に設定されたものと同じになります。完璧な理にかなって
function titleicon_admin_settings() {
$settings = variable_get('titleicon_settings', $default);
//build an array of primary link titles
$primary_links_items = menu_primary_links();
foreach ($primary_links_items as $item) {
$title = $item['attributes']['title'];
$href = $item['href'];
$titles[$href] = $title;
}
//build array of icons
$directory = file_directory_path() . '/icons';
$mask = '(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG)';
$icons = file_scan_directory($directory, $mask);
foreach ($icons as $icon) {
$name = $icon->name;
$path = base_path() . $icon->filename;
$html = '<img src="' . $path . '" width="50" height="50" />';
$default_value = $settings[$name]['page'];
$form[$name] = array(
'#type' => 'fieldset',
'#title' => $name,
);
$form[$name]['path_to_icon'] = array(
'#type' => 'value',
'#value' => $path,
);
$form[$name]['icon'] = array(
'#type' => 'markup',
'#value' => $html,
);
$form[$name]['page'] = array(
'#type' => 'select',
'#title' => t('Show icon on page'),
'#default_value' => $default_value,
'#description' => t('Choose which page to show icon on.'),
'#options' => $titles,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
ご協力いただきありがとうございます。今すぐご利用いただけます。 '$ name'の命名について - 私はDrupalishを改良したり、作ることができるいくつかの分野があると思います! – splatio