class PartyUserDataSetUIAttach in Party 8.2
Same name and namespace in other branches
- 7 modules/party_user/includes/party_user.data_ui.inc \PartyUserDataSetUIAttach
The 'attach' action: attach an existing entity.
Hierarchy
- class \PartyDefaultDataSetUIAttach implements PartyDataSetActionInterface
- class \PartyUserDataSetUIAttach
Expanded class hierarchy of PartyUserDataSetUIAttach
1 string reference to 'PartyUserDataSetUIAttach'
- party_user_party_data_set_info in modules/
party_user/ party_user.module - Implements hook_party_data_set_info()
File
- modules/
party_user/ includes/ party_user.data_ui.inc, line 10 - Provides classes for UI actions on the user data set.
View source
class PartyUserDataSetUIAttach extends PartyDefaultDataSetUIAttach {
/**
* Provides the action form for attaching an existing user.
*
* @param $party
* A loaded party object.
* @param $data_set
* A loaded data set.
* We don't actually need this loaded, but we need a menu loader to convert
* the path-style string to the machine name, and a menu loader that doesn't
* load would be weird too.
* @param $eid
* The id of the entity, if relevant to this action.
*/
function action_form($form, &$form_state, $party, $data_set, $eid = NULL) {
$form = array();
$form['user'] = array(
'#type' => 'textfield',
'#title' => t('User'),
'#maxlength' => 60,
'#autocomplete_path' => 'user/autocomplete',
'#description' => t('Enter the username of the account to attach.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Attach user'),
'#weight' => 99,
);
return $form;
}
function action_form_validate($form, &$form_state) {
// Validate the user name.
$account = user_load_by_name($form_state['values']['user']);
if (!$account) {
form_set_error('user', t('The username %name does not exist.', array(
'%name' => $form_state['values']['user'],
)));
}
}
function action_form_submit($form, &$form_state) {
// Get the original form parameters.
list($party, $data_set, $action, $eid) = $form_state['build_info']['args'];
// Attempt to load a user from the given input.
$account = user_load_by_name($form_state['values']['user']);
if ($account->uid != 0) {
// Attach the user entity to the party.
$data_set_controller = party_get_crm_controller($party, $data_set['set_name']);
$data_set_controller
->attachEntity($account);
$data_set_controller
->save();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PartyDefaultDataSetUIAttach:: |
function |
The page title for the action form. Overrides PartyDataSetActionInterface:: |
||
PartyUserDataSetUIAttach:: |
function |
Provides the action form for attaching an existing user. Overrides PartyDefaultDataSetUIAttach:: |
||
PartyUserDataSetUIAttach:: |
function |
Form submission for the action form. Overrides PartyDefaultDataSetUIAttach:: |
||
PartyUserDataSetUIAttach:: |
function |
Form validation for the action form. Overrides PartyDefaultDataSetUIAttach:: |