public static function LingotekJobId::processJobId in Lingotek Translation 4.0.x
Same name and namespace in other branches
- 8.2 src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.0.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.1.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.2.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.3.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.4.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.5.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.6.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.7.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
- 3.8.x src/Element/LingotekJobId.php \Drupal\lingotek\Element\LingotekJobId::processJobId()
Processes a machine-readable name form element.
Parameters
array $element: The form element to process. See main class documentation for properties.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array The processed element.
File
- src/
Element/ LingotekJobId.php, line 97
Class
- LingotekJobId
- Provides a job id render element.
Namespace
Drupal\lingotek\ElementCode
public static function processJobId(&$element, FormStateInterface $form_state, &$complete_form) {
// Apply default form element properties.
$element += [
'#title' => t('Job ID'),
'#description' => t('Assign a job id that you can filter on later on the TMS or in this page.'),
'#job_id' => [],
'#size' => 50,
];
// A form element that doesn't need to set any #job_id property would leave
// all properties undefined, if the defaults were defined by an element
// plugin. Therefore, we apply the defaults here.
$element['#job_id'] += [
'element' => '#' . $element['#id'],
'label' => t('Job ID'),
'pattern' => '[^\\/\\]+',
// We need an extra \ because this is consumed by the JS.
'replace_pattern' => '[\\/\\\\]+',
'replace' => '-',
];
// By default, machine names are restricted to Latin alphanumeric characters.
// So, default to LTR directionality.
if (!isset($element['#attributes'])) {
$element['#attributes'] = [];
}
$element['#attributes'] += [
'dir' => LanguageInterface::DIRECTION_LTR,
];
$element['#attached']['library'][] = 'lingotek/lingotek.job';
$options = [
'replace_pattern',
'replace',
'element',
'label',
];
$element['#attached']['drupalSettings']['lingotekJobId']['#' . $element['#id']] = array_intersect_key($element['#job_id'], array_flip($options));
return $element;
}