You are here

public function MaestroReassign::submitForm in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/MaestroReassign.php \Drupal\maestro\Form\MaestroReassign::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/MaestroReassign.php, line 149

Class

MaestroReassign
The Maestro Reassign form.

Namespace

Drupal\maestro\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // We do the reassignment here.
  $assign_type = $form_state
    ->getValue('assign_type');
  $entity = '';
  if ($assign_type == 'user') {
    $uid = $form_state
      ->getValue('select_assigned_user');

    // This now holds the user ID.  translate that into username.
    $account = User::load($uid);
    $entity = $account
      ->getDisplayName();
  }
  elseif ($assign_type == 'role') {
    $entity = $form_state
      ->getValue('select_assigned_role');
  }
  else {

    // TODO: offload to module to do validation of whatever assign type this is
    // set the $entity variable here.
  }
  if (isset($entity)) {

    // Set the field here.
    $assignmentID = $form_state
      ->getValue('assignment_id');
    $assignRecord = \Drupal::entityTypeManager()
      ->getStorage('maestro_production_assignments')
      ->load($assignmentID);
    if ($assignRecord) {
      $assignRecord
        ->set('assign_id', $entity);

      // We force this to be by fixed value now.
      $assignRecord
        ->set('by_variable', '0');
      $assignRecord
        ->save();
    }
  }
}