Задача: изменить вид выбора атрибутов товара с выпадающего списка (селекта) на радиокнопки.
Решение:
Создаем модуль и помещаем в него следующий код:
<?php
function MODULENAME_form_alter(&$form, &$form_state, $form_id)
{
if (strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0 && isset($form['product_id']))
{
// Sanitization of select options will occur in a check_plain() in
// the function form_select_options(). We change this element to
// another #type, 'radios', and hence we are also responsible for looping
// over its #options array and sanitizing the values.
if (isset($form['attributes']['product_select']))
{
foreach($form['attributes']['product_select']['#options'] as $key => $value)
{
$form['attributes']['product_select']['#options'][$key] = check_plain($value);
}
// Change element to #type radios.
$form['attributes']['product_select']['#type'] = "radios";
}
}
}
Было:
Стало:
Код написан на основе https://www.drupal.org/node/1364510
Добавить комментарий