You are here

protected function ModuleNameForm::copyFormValuesToEntity in Module Builder 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 ComponentSectionForm::copyFormValuesToEntity

File

src/Form/ModuleNameForm.php, line 103

Class

ModuleNameForm
Form for editing basic information, and also for adding new module entities.

Namespace

Drupal\module_builder\Form

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  if ($this->entity instanceof EntityWithPluginCollectionInterface) {

    // Do not manually update values represented by plugin collections.
    $values = array_diff_key($values, $this->entity
      ->getPluginCollections());
  }

  // Set the base properties.
  foreach ([
    'name',
    'id',
  ] as $key) {
    $entity
      ->set($key, $values[$key]);

    // Remove so it doesn't end up in the $entity->data array.
    unset($values[$key]);
  }

  // Call the parent to set the data array properties.
  parent::copyFormValuesToEntity($entity, $form, $form_state);
}