You are here

protected function ImageZoomOptionsForm::copyFormValuesToEntity in Image Zoom 8.3

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/ImageZoomOptionsForm.php, line 127

Class

ImageZoomOptionsForm
Class ImageZoomOptionsForm.

Namespace

Drupal\imagezoom\Form

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
  $options = [];
  $values = $form_state
    ->getValues();
  foreach ($values as $key => $value) {
    if (in_array($key, [
      'label',
      'id',
    ])) {
      $entity
        ->set($key, $value);
    }
    else {
      $options[$key] = $value;
    }
  }
  $entity
    ->set('options', $options);
}