You are here

public function EntityForm::getForm in Acquia Content Hub 8

Get Form.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

Return value

array Acquia Content Hub Entity Form.

File

src/Form/EntityForm.php, line 54

Class

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

Namespace

Drupal\acquia_contenthub\Form

Code

public function getForm(EntityInterface $entity) {

  // Don't display anything if the entity doesn't exist.
  $entity_id = $entity
    ->id();
  if (empty($entity_id)) {
    return NULL;
  }
  $imported_entity = $this->contentHubEntitiesTracking
    ->loadImportedByDrupalEntity($entity
    ->getEntityTypeId(), $entity_id);

  // If the entity is not imported, do not display form.
  if (!$imported_entity) {
    return NULL;
  }
  $form = [
    '#type' => 'details',
    '#title' => $this
      ->t('Acquia Content Hub settings'),
    '#access' => $this->currentUser
      ->hasPermission('administer acquia content hub'),
    '#group' => 'advanced',
    '#tree' => TRUE,
    '#weight' => 30,
  ];
  $has_local_change = $imported_entity
    ->hasLocalChange();
  $form['auto_update_label'] = [
    '#type' => 'markup',
    '#markup' => $has_local_change ? $this
      ->t('This syndicated content has been modified locally, therefore it is no longer automatically synchronized to its original content.') : $this
      ->t('This is a syndicated content. What happens if its original content is updated?'),
  ];
  $form['auto_update'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable this syndicated content to receive the same updates of its original content'),
    '#default_value' => $imported_entity
      ->isAutoUpdate(),
  ];
  if ($has_local_change) {
    $form['auto_update_local_changes_label'] = [
      '#type' => 'markup',
      '#markup' => '<div>' . $this
        ->t('Check to enable synchronization with any future updates of content from Content Hub.') . '</div><div><strong>' . $this
        ->t("Any edits that were made to your site's instance of this content will be overwritten by the Content Hub version.") . '</strong></div>',
    ];
  }
  return $form;
}