You are here

public function EntityForm::saveSettings in Acquia Content Hub 8

Save settings.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

File

src/Form/EntityForm.php, line 118

Class

EntityForm
Defines a form that alters entity form to add a Content Hub form.

Namespace

Drupal\acquia_contenthub\Form

Code

public function saveSettings(FormStateInterface $form_state) {
  if ($form_state
    ->isValueEmpty('acquia_contenthub')) {
    return;
  }
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $imported_entity = $this->contentHubEntitiesTracking
    ->loadImportedByDrupalEntity($entity
    ->getEntityTypeId(), $entity
    ->id());
  if (!$imported_entity) {
    return;
  }
  $values = $form_state
    ->getValue('acquia_contenthub');
  $new_auto_update_flag = $values['auto_update'];

  // If we are changing state to "sync enabled" (from anything else),
  // set state to resync entity. Otherwise, just set the new autoUpdate flag.
  $set_pending_sync = !$imported_entity
    ->isAutoUpdate() && $new_auto_update_flag === 1;
  $set_pending_sync ? $imported_entity
    ->setPendingSync() : $imported_entity
    ->setAutoUpdate($new_auto_update_flag);
  $imported_entity
    ->save();
}