「保存」コメントボタンの名前を変更する方法を知っている人はいますか?「投稿」に変更しようとしています。Drupal 7とZenサブテーマを使用しています。
「保存」コメントボタンの名前を変更する方法を知っている人はいますか?「投稿」に変更しようとしています。Drupal 7とZenサブテーマを使用しています。
回答:
Drupal 7の場合hook_form_FORM_ID_alter()、次のようなコードを使用して実装するカスタムモジュールを作成する必要があります(「mymodule」を、作成しているモジュールの短い名前に置き換えます)。
function mymodule_form_comment_form_alter(&$form, &$form_state) {
  if (isset($form['actions']['submit'])) {
    $form['actions']['submit']['#value'] = t('Post');
  }
}
comment_form()は次のコードを使用して、フォームボタンを定義します。
  // Only show the save button if comment previews are optional or if we are
  // already previewing the submission.
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit', 
    '#value' => t('Save'), 
    '#access' => ($comment->cid && user_access('administer comments')) || variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || isset($form_state['comment_preview']), 
    '#weight' => 19,
  );
  $form['actions']['preview'] = array(
    '#type' => 'submit', 
    '#value' => t('Preview'), 
    '#access' => (variable_get('comment_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED), 
    '#weight' => 20, 
    '#submit' => array('comment_form_build_preview'),
Drupal 6の場合、コードは次のようになります。
function mymodule_form_comment_form_alter(&$form, &$form_state) {
  if (isset($form['submit'])) {
    $form['submit']['#value'] = t('Post');
  }
}
if (isset($form['submit'])) {}Drupal 6ではcomment_form()、次のコードを使用してフォームボタンを定義し、変更しようとしているボタンがフォームに存在しない可能性があるため、パーツを追加しました。
  // Only show save button if preview is optional or if we are in preview mode.
  // We show the save button in preview mode even if there are form errors so that
  // optional form elements (e.g., captcha) can be updated in preview mode.
  if (!form_get_errors() && ((variable_get('comment_preview_' . $node->type, COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#weight' => 19,
    );
  }
  $form['preview'] = array(
    '#type' => 'button',
    '#value' => t('Preview'),
    '#weight' => 20,
  );
hook_form_FORM_ID_alter()。
                    Drupal 6の場合、使用hook_form_alterすることを示唆する上記の回答は機能しませんが、機能すると思います。通常、次のようにします。
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ('comment_form' == $form_id) {
    $form['submit']['#value'] = t('Post');
  }
}
これは機能しているように見え、「投稿」というテキストのボタンが表示されますが、実際には2つの問題があります。
実際にこれを機能させるには、ボタンを非表示にし、カスタムフォーム送信ハンドラーを使用する必要があります。その場合は、ここに戻って作業コードを投稿します。
カスタムモジュールや文字列オーバーライドモジュールを使用する必要はありません。settings.phpの416行目で、オーバーライドを使用して以下のコメントを外して変更します。
/**
String overrides:
To override specific strings on your site with or without enabling locale
module, add an entry to this list. This functionality allows you to change
 * a small number of your site's default English language interface strings.
 *
 * Remove the leading hash signs to enable.
 */
# $conf['locale_custom_strings_en'][''] = array(
#   'forum'      => 'Discussion board',
#   '@count min' => '@count minutes',
# );
...新しい[投稿]ボタンは実際にはフォームを送信しません...
これを修正する方法:
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id === 'comment_form') {
    // Rename submit button.
    $form['submit']['#value'] = t('Post');
    // Add new form validator.
    array_unshift($form['#validate'], 'MYMODULE_comment_form_validate');
  }
}
function MYMODULE_comment_form_validate(&$form, &$form_state) {
  // Restore native value.
  if ($form_state['values']['op'] === t('Post')) {
    $form['submit']['#value'] = t('Save');
    $form_state['values']['op'] = t('Save');
  }
}
それでおしまい!検証関数が最初に実行され、コメントモジュールがネイティブの送信値でフォームを処理します。