function length_indicator_field_widget_form_alter in Length Indicator 8
Implements hook_field_widget_form_alter().
File
- ./
length_indicator.module, line 146 - Length Indicator module hooks.
Code
function length_indicator_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
if (_length_indicator_widget_is_supported($context['widget']
->getPluginId())) {
if ($context['widget']
->getThirdPartySetting('length_indicator', 'indicator')) {
$element['#attached']['library'][] = 'length_indicator/length_indicator';
$indicator_opt = $context['widget']
->getThirdPartySetting('length_indicator', 'indicator_opt');
$element['value']['#attributes']['data-length-indicator-total'] = $indicator_opt['optimin'] + $indicator_opt['optimax'];
$element['value']['#attributes']['length-indicator-enabled'] = '';
$service_length_indicator = \Drupal::service('length_indicator.get_width_pos');
$element['length_indicator'] = [
'#theme' => 'length_indicator',
'#indicators' => $service_length_indicator
->getWidthAndPosition($indicator_opt['optimin'], $indicator_opt['optimax'], $indicator_opt['tolerance']),
];
}
}
}