class LingotekIntelligenceMetadataForm in Lingotek Translation 8.2
Same name and namespace in other branches
- 4.0.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.0.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.1.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.2.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.3.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.4.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.5.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.6.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 3.7.x src/Form/LingotekIntelligenceMetadataForm.php \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
- 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
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\lingotek\Form\LingotekIntelligenceMetadataForm
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\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LingotekIntelligenceMetadataForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
LingotekIntelligenceMetadataForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LingotekIntelligenceMetadataForm:: |
protected | function | Helper method for getting the Lingotek intelligence metadata. | |
LingotekIntelligenceMetadataForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |