Merge pull request #3719 from javiexin/ticket/13911

[ticket/13911] Add events to configure options for profile fields
This commit is contained in:
Marc Alexander 2015-07-22 10:37:16 +02:00
commit 5da50fcf6e
3 changed files with 82 additions and 2 deletions

View file

@ -79,6 +79,7 @@
<dt><label for="field_hide">{L_HIDE_PROFILE_FIELD}{L_COLON}</label><br /><span>{L_HIDE_PROFILE_FIELD_EXPLAIN}</span></dt> <dt><label for="field_hide">{L_HIDE_PROFILE_FIELD}{L_COLON}</label><br /><span>{L_HIDE_PROFILE_FIELD_EXPLAIN}</span></dt>
<dd><input type="checkbox" class="radio" id="field_hide" name="field_hide" value="1"<!-- IF S_FIELD_HIDE --> checked="checked"<!-- ENDIF --> /></dd> <dd><input type="checkbox" class="radio" id="field_hide" name="field_hide" value="1"<!-- IF S_FIELD_HIDE --> checked="checked"<!-- ENDIF --> /></dd>
</dl> </dl>
<!-- EVENT acp_profile_contact_before -->
<dl> <dl>
<dt><label for="field_is_contact">{L_FIELD_IS_CONTACT}{L_COLON}</label><br /><span>{L_FIELD_IS_CONTACT_EXPLAIN}</span></dt> <dt><label for="field_is_contact">{L_FIELD_IS_CONTACT}{L_COLON}</label><br /><span>{L_FIELD_IS_CONTACT_EXPLAIN}</span></dt>
<dd><input type="checkbox" class="radio" id="field_is_contact" name="field_is_contact" value="1"<!-- IF S_FIELD_CONTACT --> checked="checked"<!-- ENDIF --> /></dd> <dd><input type="checkbox" class="radio" id="field_is_contact" name="field_is_contact" value="1"<!-- IF S_FIELD_CONTACT --> checked="checked"<!-- ENDIF --> /></dd>

View file

@ -133,6 +133,13 @@ acp_posting_buttons_before
* Since: 3.1.0-b4 * Since: 3.1.0-b4
* Purpose: Add content before BBCode posting buttons in the ACP * Purpose: Add content before BBCode posting buttons in the ACP
acp_profile_contact_before
===
* Locations:
+ adm/style/acp_profile.html
* Since: 3.1.6-RC1
* Purpose: Add extra options to custom profile field configuration in the ACP
acp_ranks_edit_after acp_ranks_edit_after
=== ===
* Locations: * Locations:

View file

@ -31,7 +31,7 @@ class acp_profile
{ {
global $config, $db, $user, $auth, $template, $cache; global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
global $request, $phpbb_container; global $request, $phpbb_container, $phpbb_dispatcher;
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx); include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
@ -369,6 +369,32 @@ class acp_profile
'field_is_contact', 'field_is_contact',
); );
/**
* Event to add initialization for new profile field table fields
*
* @event core.acp_profile_create_edit_init
* @var string action create|edit
* @var int step Configuration step (1|2|3)
* @var bool submit Form has been submitted
* @var bool save Configuration should be saved
* @var string field_type Type of the field we are dealing with
* @var array field_row Array of data about the field
* @var array exclude Array of excluded fields by step
* @var array visibility_ary Array of fields that are visibility related
* @since 3.1.6-RC1
*/
$vars = array(
'action',
'step',
'submit',
'save',
'field_type',
'field_row',
'exclude',
'visibility_ary',
);
extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_init', compact($vars)));
$options = $profile_field->prepare_options_form($exclude, $visibility_ary); $options = $profile_field->prepare_options_form($exclude, $visibility_ary);
$cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string(request_var('field_ident', $field_row['field_ident'], true)) : request_var('field_ident', $field_row['field_ident']); $cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string(request_var('field_ident', $field_row['field_ident'], true)) : request_var('field_ident', $field_row['field_ident']);
@ -644,6 +670,33 @@ class acp_profile
break; break;
} }
$field_data = $cp->vars;
/**
* Event to add template variables for new profile field table fields
*
* @event core.acp_profile_create_edit_after
* @var string action create|edit
* @var int step Configuration step (1|2|3)
* @var bool submit Form has been submitted
* @var bool save Configuration should be saved
* @var string field_type Type of the field we are dealing with
* @var array field_data Array of data about the field
* @var array s_hidden_fields Array of hidden fields in case this needs modification
* @var array options Array of options specific to this step
* @since 3.1.6-RC1
*/
$vars = array(
'action',
'step',
'submit',
'save',
'field_type',
'field_data',
's_hidden_fields',
'options',
);
extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_after', compact($vars)));
$template->assign_vars(array( $template->assign_vars(array(
'S_HIDDEN_FIELDS' => $s_hidden_fields) 'S_HIDDEN_FIELDS' => $s_hidden_fields)
); );
@ -810,7 +863,7 @@ class acp_profile
*/ */
function save_profile_field(&$cp, $field_type, $action = 'create') function save_profile_field(&$cp, $field_type, $action = 'create')
{ {
global $db, $config, $user, $phpbb_container; global $db, $config, $user, $phpbb_container, $phpbb_dispatcher;
$field_id = request_var('field_id', 0); $field_id = request_var('field_id', 0);
@ -852,6 +905,25 @@ class acp_profile
'field_contact_url' => $cp->vars['field_contact_url'], 'field_contact_url' => $cp->vars['field_contact_url'],
); );
$field_data = $cp->vars;
/**
* Event to modify profile field configuration data before saving to database
*
* @event core.acp_profile_create_edit_save_before
* @var string action create|edit
* @var string field_type Type of the field we are dealing with
* @var array field_data Array of data about the field
* @var array profile_fields Array of fields to be sent to the database
* @since 3.1.6-RC1
*/
$vars = array(
'action',
'field_type',
'field_data',
'profile_fields',
);
extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_save_before', compact($vars)));
if ($action == 'create') if ($action == 'create')
{ {
$profile_fields += array( $profile_fields += array(