3

ノード追加フォームの画像ウィジェットの「alt」および「title」ラベルを変更しようとしています。

編集用の Drupal 7 Alt フィールドと Title フィールド

私はこれらのフックの両方を試しました:

hook_field_widget_form_alter
hook_form_alter

ラベルを正常に変更するために必要な場所を見つけることができませんでした。これにフックして変更する適切な方法を教えてください。違いがある場合は、カスタムモジュールからこれらをヒットしています。テーマを介してそれらをヒットすることも私にとっては問題ありません。

アイデアはありますか?

4

1 に答える 1

16

ウィジェット フォームに追加の Process 関数を追加する必要があります。

Develモジュールでdpm($element)を使用して、使用可能なキー、オプションなどの詳細を確認することもできます。

// Alter image Title for field_top_image instance
function MYMODULE_field_widget_form_alter(&$element, &$form_state, $context) {
  // If this is an image field type of instance 'field_image_top'
  if ($context['field']['field_name'] == 'field_image_top') {
    // Loop through the element children (there will always be at least one).
    foreach (element_children($element) as $key => $child) {
      // Add the new process function to the element
      //dpm($element);
      $element[$key]['#process'][] = 'MYMODULE_image_field_widget_process';
    }
  }
}

function MYMODULE_image_field_widget_process($element, &$form_state, $form) {
  // Change the title field label and description
  //dpm($element);
  $element['title']['#title'] = 'NEW TITLE';
  $element['title']['#description'] = 'SOME NEW DESCRIPTION HERE.';

  // Return the altered element
  return $element;
}

同様の問題を参照してください: https://drupal.stackexchange.com/questions/32861/how-do-i-alter-image-field-code-without-hacking-core

于 2013-08-23T19:12:58.143 に答える