You are here

class LingotekIntelligenceMetadataForm in Lingotek Translation 3.0.x

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

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

@package Drupal\lingotek\Form

Hierarchy

Expanded class hierarchy of LingotekIntelligenceMetadataForm

1 file declares its use of LingotekIntelligenceMetadataForm
LingotekSettingsController.php in src/Controller/LingotekSettingsController.php

File

src/Form/LingotekIntelligenceMetadataForm.php, line 14

Namespace

Drupal\lingotek\Form
View source
class LingotekIntelligenceMetadataForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'lingotek.intelligence_metadata_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $metadata = $this
      ->getIntelligenceMetadata($form_state);
    $form['intelligence_metadata'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Lingotek Intelligence Metadata'),
      '#tree' => TRUE,
    ];
    $form['intelligence_metadata']['use_author'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Content\'s Author name and email to be tracked',
      '#default_value' => $metadata
        ->getAuthorPermission(),
    ];
    $form['intelligence_metadata']['use_author_email'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'checkbox',
      '#title' => 'Enable the Content Author\'s email to be tracked',
      '#default_value' => $metadata
        ->getAuthorEmailPermission(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_author]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_contact_email_for_author'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'checkbox',
      '#title' => 'Use the Contact Email as the Author Default Email',
      '#default_value' => $metadata
        ->getContactEmailForAuthorPermission(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_author]"]' => [
            'checked' => TRUE,
          ],
          ':input[name="intelligence_metadata[use_contact_email]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['default_author_email'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Default Author Email'),
      '#description' => $this
        ->t('Only used if the Author does not have an email address'),
      '#default_value' => $metadata
        ->getDefaultAuthorEmail(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_author]"]' => [
            'checked' => TRUE,
          ],
          ':input[name="intelligence_metadata[use_author_email]"]' => [
            'checked' => TRUE,
          ],
          ':input[name="intelligence_metadata[use_contact_email_for_author]"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_business_unit'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Business Unit to be tracked',
      '#default_value' => $metadata
        ->getBusinessUnitPermission(),
    ];
    $form['intelligence_metadata']['business_unit'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Business Unit'),
      '#default_value' => $metadata
        ->getBusinessUnit(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_business_unit]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_business_division'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Business Division to be tracked',
      '#default_value' => $metadata
        ->getBusinessDivisionPermission(),
    ];
    $form['intelligence_metadata']['business_division'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Business Division'),
      '#default_value' => $metadata
        ->getBusinessDivision(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_business_division]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_campaign_id'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Campaign ID to be tracked',
      '#default_value' => $metadata
        ->getCampaignIdPermission(),
    ];
    $form['intelligence_metadata']['campaign_id'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Campaign Id'),
      '#default_value' => $metadata
        ->getCampaignId(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_campaign_id]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_campaign_rating'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Campaign Rating to be tracked',
      '#default_value' => $metadata
        ->getCampaignRatingPermission(),
    ];
    $form['intelligence_metadata']['campaign_rating'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'number',
      '#title' => $this
        ->t('Campaign Rating'),
      '#default_value' => $metadata
        ->getCampaignRating(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_campaign_rating]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_channel'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Channel to be tracked',
      '#default_value' => $metadata
        ->getChannelPermission(),
    ];
    $form['intelligence_metadata']['channel'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Channel'),
      '#default_value' => $metadata
        ->getChannel(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_channel]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_contact_name'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Contact Name to be tracked',
      '#default_value' => $metadata
        ->getContactNamePermission(),
    ];
    $form['intelligence_metadata']['contact_name'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Contact Name'),
      '#default_value' => $metadata
        ->getContactName(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_contact_name]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_contact_email'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Contact Email to be tracked',
      '#default_value' => $metadata
        ->getContactEmailPermission(),
    ];
    $form['intelligence_metadata']['contact_email'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Contact Email'),
      '#default_value' => $metadata
        ->getContactEmail(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_contact_email]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_content_description'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Content Description to be tracked',
      '#default_value' => $metadata
        ->getContentDescriptionPermission(),
    ];
    $form['intelligence_metadata']['content_description'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Content Description'),
      '#default_value' => $metadata
        ->getContentDescription(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_content_description]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_base_domain'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Base Domain to be tracked',
      '#default_value' => $metadata
        ->getBaseDomainPermission(),
      '#description' => 'This value will be pulled from the entities location and cannot be edited',
    ];
    $form['intelligence_metadata']['use_reference_url'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Reference URL to be tracked',
      '#default_value' => $metadata
        ->getReferenceUrlPermission(),
      '#description' => 'This value will be pulled from the entities location and cannot be edited',
    ];
    $form['intelligence_metadata']['use_external_style_id'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the External Style ID to be tracked',
      '#default_value' => $metadata
        ->getExternalStyleIdPermission(),
    ];
    $form['intelligence_metadata']['external_style_id'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('External Style Id'),
      '#default_value' => $metadata
        ->getExternalStyleId(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_external_style_id]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_purchase_order'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Purchase Order to be tracked',
      '#default_value' => $metadata
        ->getPurchaseOrderPermission(),
    ];
    $form['intelligence_metadata']['purchase_order'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Purchase Order'),
      '#default_value' => $metadata
        ->getPurchaseOrder(),
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_purchase_order]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['use_region'] = [
      '#type' => 'checkbox',
      '#title' => 'Enable the Region to be tracked',
      '#default_value' => $metadata
        ->getRegionPermission(),
    ];
    $form['intelligence_metadata']['region'] = [
      '#attributes' => [
        'class' => [
          'indented',
        ],
      ],
      '#type' => 'textfield',
      '#size' => 20,
      '#title' => $this
        ->t('Region'),
      '#default_value' => $metadata
        ->getRegion() ?: '',
      '#states' => [
        'visible' => [
          ':input[name="intelligence_metadata[use_region]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
    $form['intelligence_metadata']['actions'] = [
      '#type' => 'actions',
    ];
    $form['intelligence_metadata']['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save Lingotek Intelligence Metadata'),
      '#button_type' => 'primary',
    ];
    return $form;
  }

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

  /**
   * Helper method for getting the Lingotek intelligence metadata.
   *
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return LingotekIntelligenceMetadataInterface
   *   Returns the Lingotek intelligence metadata this form applies to.
   */
  protected function getIntelligenceMetadata(FormStateInterface $form_state) {
    $buildInfo = $form_state
      ->getBuildInfo();
    return $buildInfo['args'][1];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create 105
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LingotekIntelligenceMetadataForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
LingotekIntelligenceMetadataForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
LingotekIntelligenceMetadataForm::getIntelligenceMetadata protected function Helper method for getting the Lingotek intelligence metadata.
LingotekIntelligenceMetadataForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.