как переопределить функцию ?
Прислано: vrazbros
чт, 30/08/2007 - 08:15
есть в модуле fivestars функция, код ниже, добавил туда 1 строчку, но сам код модуля править не правельно. Добавил в template.php c именем phptemplate_fivestar_form_alter($form_id, &$form) { весь код + мои изменения} выдает кучу errors. Как переопределить правельно ?
function fivestar_form_alter($form_id, &$form) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['fivestar'] = array(
'#type' => 'fieldset',
'#title' => t('Five Star ratings'),
'#collapsible' => TRUE,
);
$form['workflow']['fivestar']['fivestar'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Five Star rating'),
'#default_value' => variable_get('fivestar_'. $form['#node_type']->type, 0),
'#return_value' => 1,
);
$form['workflow']['fivestar']['fivestar_unvote'] = array(
'#type' => 'checkbox',
'#title' => t('Allow users to undo their votes'),
'#default_value' => variable_get('fivestar_unvote_'. $form['#node_type']->type, 0),
'#return_value' => 1,
);
$form['workflow']['fivestar']['fivestar_stars'] = array(
'#type' => 'select',
'#title' => t('Number of stars'),
'#options' => drupal_map_assoc(array(1,2,3,4,5,6,7,8,9,10)),
'#default_value' => variable_get('fivestar_stars_'. $form['#node_type']->type, 5),
);
$form['workflow']['fivestar']['fivestar_style'] = array(
'#type' => 'select',
'#title' => t('Five Star display style'),
'#default_value' => variable_get('fivestar_style_'. $form['#node_type']->type, 'default'),
'#options' => array(
'compact' => t('Nothing but the stars'),
'notitle' => t('Without title'), /* то что я добавил */
'default' => t('Stars and average'),
'dual' => t('Two sets of stars'),
),
);
$form['workflow']['fivestar']['fivestar_position_teaser'] = array(
'#type' => 'select',
'#title' => t('Widget location (teaser)'),
'#default_value' => variable_get('fivestar_position_teaser_'. $form['#node_type']->type, 'hidden'),
'#options' => array(
'above' => t('Above the teaser body'),
'below' => t('Below the teaser body'),
'hidden' => t('Hidden'),
),
);
$form['workflow']['fivestar']['fivestar_position'] = array(
'#type' => 'select',
'#title' => t('Widget location (full node)'),
'#default_value' => variable_get('fivestar_position_'. $form['#node_type']->type, 'below'),
'#options' => array(
'above' => t('Above the node body'),
'below' => t('Below the node body'),
'hidden' => t('Hidden'),
),
);
}
}
- vrazbros's blog
- Для комментирования войдите или зарегистрируйтесь
Функцию переопределить нельзя никак. Но для твоего случая можно изменить саму форму с помощью http://api.drupal.org/api/function/hook_form_alter/5
- Для комментирования войдите или зарегистрируйтесь
очень интересно, но что то непонятно. Можно поподробней как изменить ?
- Для комментирования войдите или зарегистрируйтесь
собственно с function fivestar_form_alter($form_id, &$form) разобрался
сделал так:
<?php
function votinglibrary_form_alter($form_id, &$form) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['fivestar']['fivestar_style'] = array(
'#type' => 'select',
'#title' => t('Five Star display style'),
'#default_value' => variable_get('fivestar_style_'. $form['#node_type']->type, 'default'),
'#options' => array(
'compact' => t('Nothing but the stars'),
'notitle' => t('Without title'), <------------------------мои изменения
'default' => t('Stars and average'),
'dual' => t('Two sets of stars'),
),
);
}
}
но нужно изм еще одну ф-ю и тут я застрял
function fivestar_form($content_type, $content_id, $style = 'default') {
global $user;
$current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'average');
$current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'count');
if ($user->uid) {
$current_vote = votingapi_get_vote($content_type, $content_id, 'percent', 'vote', $user->uid);
}
else {
$current_vote->value = 0;
}
if ($content_type == 'node') {
$node = node_load($content_id);
}
$stars = variable_get('fivestar_stars_'. (!isset($node) ? 'default' : $node->type), 5);
$form = array();
$form['content_type'] = array(
'#type' => 'hidden',
'#value' => $content_type,
);
$form['content_id'] = array(
'#type' => 'hidden',
'#value' => $content_id,
);
$form['vote'] = array(
'#type' => 'fivestar',
'#stars' => $stars,
'#vote_count' => $current_count->value,
'#vote_average' => $current_avg->value,
'#default_value' => $current_vote->value,
'#auto_submit' => TRUE,
'#auto_submit_path' => 'fivestar/vote/' . $content_type . '/' . $content_id,
'#allow_clear' => variable_get('fivestar_unvote_'. (!isset($node) ? 'default' : $node->type), FALSE),
'#content_id' => $content_id,
);
switch ($style) {
case 'compact':
// We actually don't need anything more here.
break;
case 'default':
$form['vote']['#title'] = t('Your vote');
$form['vote']['#description'] = theme('fivestar_summary', $current_avg->value, $current_count->value, $stars);
break;
case 'notitle': /* то что нужно добавить */
$form['vote']['#description'] = theme('fivestar_summary', $current_avg->value, $current_count->value, $stars); /* добавить */
break; /* добавить */
case 'dual':
$form['vote']['#title'] = t('Your vote');
$form['average'] = array(
'#type' => 'item',
'#title' => t('Current rating'),
'#value' => theme('fivestar_static', $current_avg->value, $stars)
);
break;
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit rating'),
'#attributes' => array('class' => 'fivestar-submit'),
);
// Add javascript to hide the submit button.
if (strpos(drupal_get_js(), "jQuery('input.fivestar-submit').hide()") === FALSE) {
drupal_add_js("jQuery(function(){jQuery('input.fivestar-submit').hide();});", 'inline');
}
$form['#attributes']['class'] = 'fivestar-widget';
$form['#base'] = 'fivestar_form';
$form['#redirect'] = FALSE;
return $form;
}
?>- Для комментирования войдите или зарегистрируйтесь
насколько я понимаю - если одноименную функцию поместить в sites/default/settings.php то друпал будет использовать ее.
еще мне где-то попадалось решение как сделать голосование за отдельные поля ноды - но я потерял, подскажите пожалуйста
- Для комментирования войдите или зарегистрируйтесь
нет, есле создать еще одну функцию с таким же именем то получим php error redeclared function in... можно переопределить только хуки.
- Для комментирования войдите или зарегистрируйтесь


Комментарии