You are here

private function MailchimpCampaignForm::getEntityImportFormElements in Mailchimp 8

Same name and namespace in other branches
  1. 2.x modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php \Drupal\mailchimp_campaign\Form\MailchimpCampaignForm::getEntityImportFormElements()

Gets form elements used in the entity import feature.

Parameters

string $entity_type: The type of entity to import.

string $section: The content section these fields are displayed in.

Return value

array Array of form elements used to display entity imports.

1 call to MailchimpCampaignForm::getEntityImportFormElements()
MailchimpCampaignForm::form in modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php
Gets the actual form array to be built.

File

modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php, line 592

Class

MailchimpCampaignForm
Form controller for the MailchimpCampaign entity edit form.

Namespace

Drupal\mailchimp_campaign\Form

Code

private function getEntityImportFormElements($entity_type, $section) {
  $form = [];

  // Get available entity types.
  $entity_info = $this
    ->getEntitiesForContentImport();
  $entity_options = $this
    ->buildEntityOptionList($entity_info);
  $form['entity_import'] = [
    '#id' => 'entity-import',
    '#type' => 'details',
    '#title' => $this
      ->t('Insert site content'),
    '#description' => $this
      ->t('<b>For use only with text filters that use the Mailchimp Campaign filter</b><br />You can insert an entity of a given type and pick the view mode that will be rendered within this campaign section.'),
    '#open' => FALSE,
  ];
  $form['entity_import']['entity_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Entity Type'),
    '#options' => $entity_options,
    '#default_value' => $entity_type,
    '#ajax' => [
      'callback' => 'Drupal\\mailchimp_campaign\\Form\\MailchimpCampaignForm::entityTypeCallback',
      'wrapper' => $section . '-content-entity-lookup-wrapper',
    ],
  ];
  $form['entity_import']['entity_type']['#attributes']['class'][] = $section . '-entity-import-entity-type';
  $form['entity_import']['entity_import_wrapper'] = [
    '#type' => 'container',
    '#attributes' => [
      'id' => $section . '-content-entity-lookup-wrapper',
    ],
  ];
  if ($entity_type != NULL) {

    // Get available entity view modes.
    $entity_view_mode_options = $this
      ->buildEntityViewModeOptionList($entity_type);
    $form['entity_import']['entity_id'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Entity Title'),
      '#maxlength' => 255,
      // Pass entity type as first parameter to autocomplete callback.
      '#autocomplete_route_name' => 'mailchimp_campaign.entity_autocomplete',
      '#autocomplete_route_parameters' => [
        'entity_type' => $entity_type,
      ],
    ];
    $form['entity_import']['entity_id']['#attributes']['id'] = $section . '-entity-import-entity-id';
    $form['entity_import']['entity_view_mode'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('View Mode'),
      '#options' => $entity_view_mode_options,
      '#attributes' => [
        'id' => $section . '-entity-import-entity-view-mode',
      ],
    ];
  }
  $form['entity_import']['entity_import_link'] = [
    '#type' => 'item',
    '#markup' => '<a id="' . $section . '-add-entity-token-link" class="add-entity-token-link" href="javascript:void(0);">' . $this
      ->t('Insert entity token') . '</a>',
    '#states' => [
      'invisible' => [
        ':input[name="content[' . $section . '_wrapper][entity_import][entity_type]"]' => [
          'value' => '',
        ],
      ],
    ],
  ];
  $form['entity_import']['entity_import_tag'] = [
    '#type' => 'container',
    '#attributes' => [
      'id' => $section . '-entity-import-tag-field',
    ],
    '#states' => [
      'invisible' => [
        ':input[name="content[' . $section . '_wrapper][entity_import][entity_type]"]' => [
          'value' => '',
        ],
      ],
    ],
  ];
  return $form;
}