class RegistrationViewsHandlerStateEdit in Entity Registration 8.2
Same name in this branch
- 8.2 modules/registration_views/registration_views.module \RegistrationViewsHandlerStateEdit
- 8.2 modules/registration_views/src/RegistrationViewsHandlerStateEdit.php \Drupal\registration_views\RegistrationViewsHandlerStateEdit
Same name and namespace in other branches
- 8 modules/registration_views/registration_views.module \RegistrationViewsHandlerStateEdit
- 7.2 modules/registration_views/registration_views.module \RegistrationViewsHandlerStateEdit
- 7 modules/registration_views/registration_views.module \RegistrationViewsHandlerStateEdit
A Views' field handler for editing the registration state.
Hierarchy
- class \RegistrationViewsHandlerStateEdit extends \views_handler_field
Expanded class hierarchy of RegistrationViewsHandlerStateEdit
1 string reference to 'RegistrationViewsHandlerStateEdit'
- registration_views_views_data_alter in modules/
registration_views/ registration_views.module - Implements hook_views_data_alter().
File
- modules/
registration_views/ registration_views.module, line 308 - Entity Registration Views integration
View source
class RegistrationViewsHandlerStateEdit extends views_handler_field {
function construct() {
parent::construct();
$this->additional_fields['registration_id'] = 'registration_id';
$this->additional_fields['state'] = 'state';
}
function query() {
$this
->ensure_my_table();
$this
->add_additional_fields();
}
/**
* Render the field contents.
*/
function render($values) {
// Render a Views form item placeholder.
return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
}
/**
* Add to and alter the form.
*/
function views_form(&$form, &$form_state) {
// Create a container for our replacements
$form[$this->options['id']] = array(
'#type' => 'container',
'#tree' => TRUE,
);
// Iterate over the result and add our replacement fields to the form.
foreach ($this->view->result as $row_index => $row) {
// Add a text field to the form. This array convention
// corresponds to the placeholder HTML comment syntax.
$form[$this->options['id']][$row_index] = array(
'#type' => 'select',
'#default_value' => $row->{$this->aliases['state']},
'#options' => registration_get_states_options(),
'#required' => TRUE,
);
}
}
/**
* Form submit method.
*/
function views_form_submit($form, &$form_state) {
// Determine which nodes we need to update.
$updates = array();
foreach ($this->view->result as $row_index => $row) {
$value = $form_state['values'][$this->options['id']][$row_index];
if ($row->{$this->aliases['state']} != $value) {
$updates[$row->{$this->aliases['registration_id']}] = $value;
}
}
$registrations = registration_load_multiple(array_keys($updates));
foreach ($registrations as $registration_id => $registration) {
$registration->state = $updates[$registration_id];
registration_save($registration);
}
drupal_set_message(t('Updated @num registration states.', array(
'@num' => count($updates),
)));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RegistrationViewsHandlerStateEdit:: |
function | |||
RegistrationViewsHandlerStateEdit:: |
function | |||
RegistrationViewsHandlerStateEdit:: |
function | Render the field contents. | ||
RegistrationViewsHandlerStateEdit:: |
function | Add to and alter the form. | ||
RegistrationViewsHandlerStateEdit:: |
function | Form submit method. |