2013-08-23 3 views
2

노드 추가 양식에서 이미지 위젯의"alt "및"title "레이블을 변경하려고합니다.Drupal 7 : 이미지 필드 위젯 "alt"또는 제목 "label을 변경하는 방법

Drupal 7 Alt and Title fields for editing

나는이 후크를 모두 시도 : 나는 성공적으로 라벨을 변경 갈 필요가 어디 있는지 찾을 수 없습니다

hook_field_widget_form_alter 
hook_form_alter 

. 어떤 사람들이 나를 연결하여 적절하게 연결하여 변경할 수 있습니까? 차이가 있다면 커스텀 모듈에서 이들을 치고 있습니다. 주제를 통해 그들을 쳐도 괜찮을 것입니다.

아무도 아이디어가 없습니까?

답변

14

위젯 양식에을 추가하려면 추가 기능을 추가해야합니다. https://drupal.stackexchange.com/questions/32861/how-do-i-alter-image-field-code-without-hacking-core

+0

을 근무 :

또한, 옵션 등

// 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; } 

사용 가능한 키에 대한 자세한 내용을 찾을 비슷한 문제를 볼 Devel 모듈 DPM ($ 요소)를 사용할 수 있습니다. 감사! 덕분에 – Jnicola

+0

! 좋은 상용구 솔루션. – oknate

+0

이미지의 제목/설명/제목으로 제목을 사용하는 경우 제목을 alt보다 높게 지정하려면 니스, 또한 가중치를 변경할 수 있습니다. 예 : $ element [ 'title'] [ '# weight'] = 1; $ element [ 'alt'] [ '# weight'] = 2; – klidifia