You are here

protected function FormsStepsEditForm::copyFormValuesToEntity in Forms Steps 8

Copies top-level form values to entity properties

This should not change existing entity properties that are not being edited by this form.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the current form should operate upon.

array $form: A nested array of form elements comprising the form.

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

Overrides EntityForm::copyFormValuesToEntity

File

src/Form/FormsStepsEditForm.php, line 395

Class

FormsStepsEditForm
Provides a form to edit a Forms Steps.

Namespace

Drupal\forms_steps\Form

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {

  // This form can only set the forms steps ID, label and the weights
  // for each step.

  /** @var \Drupal\forms_steps\FormsStepsInterface $entity */
  $values = $form_state
    ->getValues();
  $entity
    ->set('label', $values['label']);
  $entity
    ->set('id', $values['id']);
  $entity
    ->set('description', $values['description']);
  $entity
    ->set('progress_steps_links_saved_only', $values['progress_steps_links_saved_only']);
  $entity
    ->set('progress_steps_links_saved_only_next', $values['progress_steps_links_saved_only_next']);
  $entity
    ->set('redirection_policy', $values['redirection_policy']);
  $entity
    ->set('redirection_target', $values['redirection_target']);
  if (!empty($values['steps'])) {
    foreach ($values['steps'] as $step_id => $step_values) {
      $entity
        ->setStepWeight($step_id, $step_values['weight']);
    }
  }
  if (!empty($values['progress_steps'])) {
    foreach ($values['progress_steps'] as $progress_step_id => $progress_step_values) {
      $entity
        ->setProgressStepWeight($progress_step_id, $progress_step_values['weight']);
    }
  }
}