RegistrationViewsHandlerStateEdit.php in Entity Registration 8.2
File
modules/registration_views/src/RegistrationViewsHandlerStateEdit.php
View source
<?php
namespace Drupal\registration_views;
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();
}
function render($values) {
return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
}
function views_form(&$form, &$form_state) {
$form[$this->options['id']] = array(
'#type' => 'container',
'#tree' => TRUE,
);
foreach ($this->view->result as $row_index => $row) {
$form[$this->options['id']][$row_index] = array(
'#type' => 'select',
'#default_value' => $row->{$this->aliases['state']},
'#options' => registration_get_states_options(),
'#required' => TRUE,
);
}
}
function views_form_submit($form, &$form_state) {
$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),
)));
}
}