[РЕШЕНО] Проблема с тегом alt в кнопке поиска изображения

Главные вкладки

Аватар пользователя animan animan 7 июля 2015 в 20:22

Есть такая тема mayo, для меня очень удобная. У меня стоит версия 7.x-1.3, на новую обновлятся не стал. Вот есть такая проблемка, что б пройти валидацию на сайте https://validator.w3.org/, нужно исправить ошибку:

<input type="image" src="/sites/all/themes/mayo/images/search-submit.png" class="form-submit" />

И вот в форме нужно прописать alt к изображению, но я покопался в файле template.php и нашел там такое:

<?php
$variables
['form']['actions']['submit'] = array('#type' => 'image_button''#src' => base_path() . path_to_theme() . '/images/search-submit.png');
?>

Пробовал добавлять в массив '#alt' => t('Search'), но не помогло. Может у кого-то есть идеи как решить вопрос?

Лучший ответ

Аватар пользователя sas@drupal.org sas@drupal.org 8 июля 2015 в 17:31

Пример

**
 * Returns HTML for an image button form element.
 *
 * @param $variables
 *   An associative array containing:
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #attributes, #button_type, #name, #value, #title, #src.
 *
 * @ingroup themeable
 */
function theme_image_button($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'image';
  element_set_attributes($element, array('id', 'name', 'value'));

  $element['#attributes']['src'] = file_create_url($element['#src']);
  if (!empty($element['#title'])) {
    $element['#attributes']['alt'] = $element['#title'];
    $element['#attributes']['title'] = $element['#title'];
  }

  $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
  if (!empty($element['#attributes']['disabled'])) {
    $element['#attributes']['class'][] = 'form-button-disabled';
  }

  return '<input' . drupal_attributes($element['#attributes']) . ' />';
}

Комментарии

Аватар пользователя animan animan 8 июля 2015 в 16:20

"<a href="mailto:sas@drupal.org">sas@drupal.org</a>" wrote:

myTheme_image_button($variables){
...
}


А можно немного подробней?) хотя б пример наведите.

Аватар пользователя sas@drupal.org sas@drupal.org 8 июля 2015 в 17:31

Пример

**
 * Returns HTML for an image button form element.
 *
 * @param $variables
 *   An associative array containing:
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #attributes, #button_type, #name, #value, #title, #src.
 *
 * @ingroup themeable
 */
function theme_image_button($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'image';
  element_set_attributes($element, array('id', 'name', 'value'));

  $element['#attributes']['src'] = file_create_url($element['#src']);
  if (!empty($element['#title'])) {
    $element['#attributes']['alt'] = $element['#title'];
    $element['#attributes']['title'] = $element['#title'];
  }

  $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
  if (!empty($element['#attributes']['disabled'])) {
    $element['#attributes']['class'][] = 'form-button-disabled';
  }

  return '<input' . drupal_attributes($element['#attributes']) . ' />';
}