You are here

function acquia_contenthub_unsubscribe_form_alter in Acquia Content Hub 8.2

Implements hook_form_alter().

File

modules/acquia_contenthub_unsubscribe/acquia_contenthub_unsubscribe.module, line 19
Drupal Module: Acquia Content Hub unsubscribe.

Code

function acquia_contenthub_unsubscribe_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // This is an entity form.
  if (!in_array('Drupal\\Core\\Entity\\EntityFormInterface', class_implements($form_state
    ->getFormObject()))) {
    return;
  }

  /** @var \Drupal\Core\Entity\EntityFormInterface $object */
  $object = $form_state
    ->getFormObject();
  $entity = $object
    ->getEntity();
  if (!$entity) {
    return;
  }

  // If no id assigned yet, it's not remote.
  if (!$entity
    ->id()) {
    return;
  }

  /** @var \Drupal\acquia_contenthub_subscriber\SubscriberTracker $tracker */
  $tracker = \Drupal::service('acquia_contenthub_subscriber.tracker');

  // Don't alter entities not tracked by the subscriber.
  if (!$tracker
    ->isTracked($entity
    ->uuid())) {
    return;
  }
  $status = $tracker
    ->getStatusByTypeId($entity
    ->getEntityTypeId(), $entity
    ->id());
  $status = $status === SubscriberTracker::AUTO_UPDATE_DISABLED ? TRUE : FALSE;
  $form['acquia_contenthub_subscriber_sync'] = [
    '#type' => 'checkbox',
    '#title' => t("Disable auto updating of this entity"),
    '#description' => t("Disabling auto updating will prevent this entity from being updated by Acquia ContentHub in the future."),
    '#default_value' => $status,
    '#weight' => 1000,
    '#access' => FALSE,
  ];
  if (isset($form['actions']['submit'])) {
    $form['actions']['submit']['#submit'][] = 'acquia_contenthub_subscriber_sync_state_submit';
  }
}