function maxlength_field_widget_settings_summary_alter in Maxlength 8
Implements hook_field_widget_settings_summary_alter().
File
- ./
maxlength.module, line 106 - Limits the number of characters in textfields and textareas and shows the amount of characters left.
Code
function maxlength_field_widget_settings_summary_alter(&$summary, $context) {
$plugin_id = $context['widget']
->getPluginId();
$widget_settings = \Drupal::service('maxlength.widget_settings');
$allowed_settings = $widget_settings
->getAllowedSettings($plugin_id);
if (!empty($allowed_settings)) {
if (!empty($allowed_settings['maxlength_setting']) && $context['widget']
->getThirdPartySetting('maxlength', 'maxlength_js')) {
$summary[] = t('Max length: @count', array(
'@count' => $context['widget']
->getThirdPartySetting('maxlength', 'maxlength_js'),
));
}
if (!empty($allowed_settings['summary_maxlength_setting']) && $context['widget']
->getThirdPartySetting('maxlength', 'maxlength_js_summary')) {
$summary[] = t('Max summary length: @count', array(
'@count' => $context['widget']
->getThirdPartySetting('maxlength', 'maxlength_js_summary'),
));
}
if (!empty($allowed_settings['truncate_setting'])) {
if ($context['widget']
->getThirdPartySetting('maxlength', 'maxlength_js_truncate_html')) {
$summary[] = t('Max length - Safe truncate html');
}
elseif ($context['widget']
->getThirdPartySetting('maxlength', 'maxlength_js_enforce')) {
$summary[] = t('Max length - Force truncate');
}
}
}
}