diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php index ce78a40..b8df4b2 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php @@ -62,4 +62,25 @@ public static function schema(FieldDefinitionInterface $field_definition) { ); } + /** + * {@inheritdoc} + */ + public function getConstraints() { + $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager(); + $constraints = parent::getConstraints(); + + if ($max_length = $this->getFieldSetting('max_length')) { + $constraints[] = $constraint_manager->create('ComplexData', array( + 'value' => array( + 'Length' => array( + 'max' => $max_length, + 'maxMessage' => t('%name: the text may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length)), + ) + ), + )); + } + + return $constraints; + } + } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 5757bf3..e9c31e3 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -707,6 +707,7 @@ function field_hook_info() { * Implements hook_field_info_alter(). */ function field_field_info_alter(&$info) { + // Let core's field types to have formatters and widgets. $info['string']['default_formatter'] = 'text_plain'; $info['integer']['default_formatter'] = 'text_plain'; diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 2e7497c..95a4326 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -194,8 +194,8 @@ function text_filter_format_disable($format) { * Implements hook_field_formatter_info_alter(). */ function text_field_formatter_info_alter(&$info) { - // Let a new field type re-use an existing formatter. - $info['text_plain']['field types'][] = 'text'; - $info['text_plain']['field types'][] = 'text_long'; - $info['text_plain']['field types'][] = 'text_with_summary'; + // Let a new field types to re-use an existing formatter. + $info['text_plain']['field_types'][] = 'text'; + $info['text_plain']['field_types'][] = 'text_long'; + $info['text_plain']['field_types'][] = 'text_with_summary'; }