Drupal 7サイト ユーザーポイントモジュール を使用して構築しています。
解決できない問題がいくつかあります。問題は here で確認できます。 「私のユーザーポイント」ページ(すべてのユーザーがポイントとポイントを確認できるページ)のHTMLを編集できれば、これらの問題を回避できます。
どうすればそれを達成できますか?
このページのHTMLをどこでどのように見つけ、HTMLコードを編集および追加できますか?
「My User Points」ページに定義されているメニューパスは、hook_menu実装のuserpoints.moduleファイルにあります。
$items['myuserpoints'] = array(
'title' => 'My !points',
'title arguments' => userpoints_translation(),
'page callback' => 'drupal_get_form',
'page arguments' => array('userpoints_list_transactions'),
'access callback' => 'userpoints_access_my_points',
'file' => 'userpoints.pages.inc',
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'user-menu',
);
上記のように..
引数が「userpoints_list_transactions」のページコールバックdrupal_get_fromは、「userpoints.pages.inc」ファイルで定義されています...
/**
* Displays a detailed transaction report for an individual user.
*
* @param $account
* For which account to display. Defaults to the current user.
*/
function userpoints_list_transactions($form, &$form_state, $account = NULL, $tid = NULL) {
// If this is an AJAX request, update $_GET['q'] so that table sorting and
// similar links are using the correct base path.
if ($_GET['q'] == 'system/ajax') {
$q = 'myuserpoints';
if (!empty($account)) {
$q = 'user/' . $account->uid . '/points';
}
$_GET['q'] = $q;
}
if (empty($account)) {
global $user;
$account = $user;
}
$settings = array(
'show_user' => FALSE,
);
$header = userpoints_get_transaction_header($settings);
$query = db_select('userpoints_txn', 'p')->extend('PagerDefault')->extend('TableSort')
->fields('p')
->condition('p.uid', $account->uid)
->orderByHeader($header)
// Enforce consistent sort order.
->orderBy('p.txn_id', 'DESC')
->limit(variable_get(USERPOINTS_REPORT_LIMIT, 10));
if (module_exists('taxonomy')) {
$query->leftJoin('taxonomy_term_data', 't', 'p.tid = t.tid');
}
$unapproved_query = db_select('userpoints_txn', 'p')
->condition('uid', $account->uid)
->condition('status', USERPOINTS_TXN_STATUS_PENDING);
$unapproved_query->addExpression('SUM(points)');
$values = userpoints_filter_parse_input($form_state, $tid);
$active_category = userpoints_filter_query($query, $values);
userpoints_filter_query($unapproved_query, $values);
if (isset($active_category)) {
drupal_set_title(t('!Points for @username (%category category)', userpoints_translation() + array('%category' => $active_category, '@username' => format_username($account))), PASS_THROUGH);
$total_title = t('Total !points (%category category)', userpoints_translation() + array('%category' => $active_category));
}
else {
drupal_set_title(t('!Points for @username', userpoints_translation() + array('@username' => format_username($account))));
$total_title = t('Total !points', userpoints_translation());
}
$rows = array();
foreach ($query->execute() as $transaction) {
$rows[] = userpoints_get_transaction_row($transaction, $settings);
}
// Store context in the output array so that modules have access to it.
$output = array(
'#account' => $account,
'#attached' => array(
'css' => array(
drupal_get_path('module', 'userpoints') . '/userpoints.css',
),
),
);
$output['form'] = userpoints_filter_form($account, $values);
$output['list'] = array(
'#type' => 'container',
'#id' => 'userpoints_list_wrapper',
);
$output['list']['table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No !Points earned', userpoints_translation()),
'#weight' => -5,
'#attributes' => array('class' => array('userpoints-myuserpoints-list')),
);
$output['list']['pager'] = array(
'#markup' => theme('pager'),
'#weight' => 0,
);
// Fetch pending (not yet approved) points according to the category filter.
$pending = (int)$unapproved_query
->execute()
->fetchField();
// Display both pending and approved points in a simple table.
$output['list']['summary_table'] = array(
'#theme' => 'table',
'#header' => array(
array(
'data' => $total_title,
'colspan' => 2,
),
),
'#rows' => array(
array(
'data' => array(t('Approved !points', userpoints_translation()), userpoints_get_current_points($account->uid, isset($values['tid']) ? $values['tid'] : 'all')),
'class' => array('userpoints-myuserpoints-total-approved'),
),
array(
'data' => array(t('Pending !points', userpoints_translation()), $pending),
'class' => array('userpoints-myuserpoints-total-pending'),
),
),
'#weight' => 10,
'#attributes' => array('class' => array('userpoints-myuserpoints-total')),
);
// For simplicity, the generated output is passed to a custom alter function.
// This would also be possible through hook_page_alter(), but that hook is
// hard to use.
drupal_alter('userpoints_list_transactions', $output);
return $output;
}
最後に、生成された出力がカスタム変更関数に渡されることがわかります
drupal_alter('userpoints_list_transactions', $output);
カスタムモジュールにhook_TYPE_alter()を実装することにより、出力を変更できます。つまり、実装する必要があるYOURMODULENAME_userpoints_list_transactions_alter関数です。
/**
* Implements hook_userpoints_list_transactions().
*/
function MODULENAME_userpoints_list_transactions_alter(&$output) {
// you can now change $output directly here
}
$ outputはフォーム変数です。新しい要素を$ outputに追加できます。
/**
* Implements hook_userpoints_list_transactions().
*/
function MODULENAME_userpoints_list_transactions_alter(&$output) {
// you can now change $output directly here
$output['custom_text']['my_link'] = array(
'#markup' => l("LINK", "Your Link"),
);
$output['custom_text']['my_text'] = array(
'#markup' => 'Blah Blah',
);
}