You are here

protected function TemplateForm::copyFormValuesToEntity in Workbench Email 8

Same name and namespace in other branches
  1. 2.x src/Form/TemplateForm.php \Drupal\workbench_email\Form\TemplateForm::copyFormValuesToEntity()

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/TemplateForm.php, line 300

Class

TemplateForm
Class TemplateForm.

Namespace

Drupal\workbench_email\Form

Code

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

  // Filter out unchecked items.
  $types = [];
  foreach (array_filter($form_state
    ->getValue('enabled_recipient_types')) as $type) {
    $types[$type] = [
      'status' => TRUE,
      'settings' => $form_state
        ->getValue([
        'recipient_types',
        $type,
        'settings',
      ]),
    ];
  }
  $entity
    ->set('recipient_types', $types);
  $entity
    ->set('bundles', array_filter($entity
    ->get('bundles')));
}