You are here

public function LingotekIntelligenceMetadataForm::submitForm in Lingotek Translation 3.8.x

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  2. 4.0.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  3. 3.0.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  4. 3.1.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  5. 3.2.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  6. 3.3.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  7. 3.4.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  8. 3.5.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  9. 3.6.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()
  10. 3.7.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm::submitForm()

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/LingotekIntelligenceMetadataForm.php, line 315

Class

LingotekIntelligenceMetadataForm
Helper class for creating the form for setting up the intelligence metadata.

Namespace

Drupal\lingotek\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $metadata = $this
    ->getIntelligenceMetadata($form_state);
  $metadata
    ->setAuthorPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_author',
  ]) ? TRUE : FALSE);
  $metadata
    ->setAuthorEmailPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_author_email',
  ]) ? TRUE : FALSE);
  $metadata
    ->setContactEmailForAuthorPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_contact_email_for_author',
  ]) ? TRUE : FALSE);
  $metadata
    ->setDefaultAuthorEmail($form_state
    ->getValue([
    'intelligence_metadata',
    'default_author_email',
  ]));
  $metadata
    ->setBusinessUnitPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_business_unit',
  ]) ? TRUE : FALSE);
  $metadata
    ->setBusinessUnit($form_state
    ->getValue([
    'intelligence_metadata',
    'business_unit',
  ]));
  $metadata
    ->setBusinessDivisionPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_business_division',
  ]) ? TRUE : FALSE);
  $metadata
    ->setBusinessDivision($form_state
    ->getValue([
    'intelligence_metadata',
    'business_division',
  ]));
  $metadata
    ->setCampaignIdPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_campaign_id',
  ]) ? TRUE : FALSE);
  $metadata
    ->setCampaignId($form_state
    ->getValue([
    'intelligence_metadata',
    'campaign_id',
  ]));
  $metadata
    ->setCampaignRatingPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_campaign_rating',
  ]) ? TRUE : FALSE);
  $metadata
    ->setCampaignRating(intval($form_state
    ->getValue([
    'intelligence_metadata',
    'campaign_rating',
  ])));
  $metadata
    ->setChannelPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_channel',
  ]) ? TRUE : FALSE);
  $metadata
    ->setChannel($form_state
    ->getValue([
    'intelligence_metadata',
    'channel',
  ]));
  $metadata
    ->setContactNamePermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_contact_name',
  ]) ? TRUE : FALSE);
  $metadata
    ->setContactName($form_state
    ->getValue([
    'intelligence_metadata',
    'contact_name',
  ]));
  $metadata
    ->setContactEmailPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_contact_email',
  ]) ? TRUE : FALSE);
  $metadata
    ->setContactEmail($form_state
    ->getValue([
    'intelligence_metadata',
    'contact_email',
  ]));
  $metadata
    ->setContentDescriptionPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_content_description',
  ]) ? TRUE : FALSE);
  $metadata
    ->setContentDescription($form_state
    ->getValue([
    'intelligence_metadata',
    'content_description',
  ]));
  $metadata
    ->setBaseDomainPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_base_domain',
  ]) ? TRUE : FALSE);
  $metadata
    ->setReferenceUrlPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_reference_url',
  ]) ? TRUE : FALSE);
  $metadata
    ->setExternalStyleIdPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_external_style_id',
  ]) ? TRUE : FALSE);
  $metadata
    ->setExternalStyleId($form_state
    ->getValue([
    'intelligence_metadata',
    'external_style_id',
  ]));
  $metadata
    ->setPurchaseOrderPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_purchase_order',
  ]) ? TRUE : FALSE);
  $metadata
    ->setPurchaseOrder($form_state
    ->getValue([
    'intelligence_metadata',
    'purchase_order',
  ]));
  $metadata
    ->setRegionPermission($form_state
    ->getValue([
    'intelligence_metadata',
    'use_region',
  ]) ? TRUE : FALSE);
  $metadata
    ->setRegion($form_state
    ->getValue([
    'intelligence_metadata',
    'region',
  ]));

  // Show this message only if we are saving the general settings. For profiles
  // it's not needed.
  if ($metadata instanceof LingotekIntelligenceServiceConfig) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Lingotek Intelligence Metadata saved correctly.'));
  }
}