You are here

public function ShareMessageForm::buildEntity in Share Message 8

Builds an updated entity object based upon the submitted form values.

For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.

Parameters

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

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

Return value

\Drupal\Core\Entity\EntityInterface An updated copy of the form's entity object.

Overrides EntityForm::buildEntity

See also

\Drupal\Core\Entity\EntityFormInterface::getEntity()

File

src/Form/ShareMessageForm.php, line 379

Class

ShareMessageForm
Base form controller for Share Message edit forms.

Namespace

Drupal\sharemessage\Form

Code

public function buildEntity(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\sharemessage\ShareMessageInterface $sharemessage */
  $sharemessage = parent::buildEntity($form, $form_state);
  if (!$sharemessage
    ->getSetting('override_default_settings')) {
    $sharemessage->settings = [];
  }

  // Store the selected content entities where the Share Message will be
  // displayed as an extra field into the config entity. Otherwise unset
  // extra_field_bundles if no specific entity type has been selected.
  $sharemessage
    ->setExtraFieldEntityType($form_state
    ->getValue('entity_type'));
  $sharemessage
    ->setExtraFieldBundles($form_state
    ->hasValue('bundles') ? array_keys(array_filter($form_state
    ->getValue('bundles'))) : []);

  // Move the override field into the settings array.
  //    if (\Drupal::config('sharemessage.settings')->get('message_enforcement')) {
  //      $sharemessage->settings['enforce_usage'] = $sharemessage->enforce_usage;
  //      unset($sharemessage->enforce_usage);
  //    }
  return $sharemessage;
}