You are here

public function MigratePull::buildForm in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 modules/cms_content_sync_migrate_acquia_content_hub/src/Form/MigratePull.php \Drupal\cms_content_sync_migrate_acquia_content_hub\Form\MigratePull::buildForm()
  2. 2.1.x modules/cms_content_sync_migrate_acquia_content_hub/src/Form/MigratePull.php \Drupal\cms_content_sync_migrate_acquia_content_hub\Form\MigratePull::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides MigrationBase::buildForm

File

modules/cms_content_sync_migrate_acquia_content_hub/src/Form/MigratePull.php, line 40

Class

MigratePull
Migrate a Acquia Content Hub Filter to Content Sync.

Namespace

Drupal\cms_content_sync_migrate_acquia_content_hub\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $content_hub_filter_id = NULL) {

  // @todo Is it possible to load the argument within the constructer?
  $this->content_hub_filter_id = $content_hub_filter_id;
  $this->migrationType = 'pull';
  $content_hub_filter = $this->entityTypeManager
    ->getStorage('contenthub_filter')
    ->load($this->content_hub_filter_id);
  $this->content_hub_filter = $content_hub_filter;
  $publish_setting = $this->content_hub_filter->publish_setting;
  $from_date = $this->content_hub_filter->from_date;
  $to_date = $this->content_hub_filter->to_date;
  $sources = $this->content_hub_filter->source;
  $content_hub_entity_types = $content_hub_filter
    ->getEntityTypes();
  $content_hub_bundles = $content_hub_filter
    ->getBundles();
  if ($publish_setting != 'none') {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Be aware that Content Sync does not support the Acquia Content Hub settings for: "Publish Setting" (Sets the Publish setting for this filter.), which is currently configured as "@value"', [
      '@value' => $publish_setting,
    ]), 'warning');
  }
  if ($from_date != '' || $to_date != '') {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Be aware that Content Sync does not support the Acquia Content Hub settings for: "Date From" (Date starting from) | "Date To" (Date until), which are currently configured as Date From: "@date_from_value" and Date To: "@date_to_value"', [
      '@date_from_value' => $from_date,
      '@date_to_value' => $to_date,
    ]), 'warning');
  }
  if ($sources != '') {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Be aware that Content Sync does not support the Acquia Content Hub settings for: "Sources" (Source origin site UUIDs, delimited by comma ",".), which is currently configured as @value', [
      '@value' => $sources,
    ]), 'warning');
  }
  if (empty($content_hub_entity_types)) {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Since none entity types have been configured within this Acquia Content Hub filter, no entity types will be configured for this pull flow.'));
  }
  if (empty($content_hub_bundles)) {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Since none bundles have been configured within this Acquia Content Hub filter, no bundles will be configured for this pull flow.'));
  }
  $form = parent::buildForm($form, $form_state);
  $url = Url::fromUri('https://edge-box.atlassian.net/wiki/spaces/SUP/pages/137232737/Update+behaviors');
  $link = Link::fromTextAndUrl(t('here'), $url);
  $link = $link
    ->toRenderable();
  $link['#attributes'] = [
    'class' => [
      'external',
    ],
  ];
  $link = render($link);
  $form['pull_updates_behavior'] = [
    '#title' => $this
      ->t('Pull updates behavior'),
    '#description' => $this
      ->t('This configuration allows to define the pull updates behaviors. Further information could be found @link.', [
      '@link' => $link,
    ]),
    '#type' => 'select',
    '#options' => [
      PullIntent::PULL_UPDATE_FORCE_AND_FORBID_EDITING => $this
        ->t('Forbid local changes and update'),
      PullIntent::PULL_UPDATE_FORCE_UNLESS_OVERRIDDEN => $this
        ->t('Update unless overridden locally'),
      PullIntent::PULL_UPDATE_FORCE => $this
        ->t('Dismiss local changes'),
      PullIntent::PULL_UPDATE_IGNORE => $this
        ->t('Ignore updates completely'),
    ],
    '#default_value' => PullIntent::PULL_UPDATE_FORCE_AND_FORBID_EDITING,
  ];
  return $form;
}