Skip to content
Snippets Groups Projects
Verified Commit b4448877 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2862922 by smustgrave, NitinLama, zaporylie, rpayanm, DanielVeza, pooja...

Issue #2862922 by smustgrave, NitinLama, zaporylie, rpayanm, DanielVeza, pooja saraah, ranjith_kumar_k_u, Abhijith S, bnjmnm, Kristen Pol, alexpott, ameymudras, murilohp: Set #maxlength for TelephoneDefaultWidget to the one specified in TelephoneItem plugin

(cherry picked from commit d5b4f005)
parent ba5b3091
No related branches found
No related tags found
22 merge requests!8394[warning] array_flip(): Can only flip STRING and INTEGER values, when saving a non-revisionable custom content entity,!7780issue 3443822: fix for 'No route found for the specified format html. Supported formats: json, xml.',!5013Issue #3071143: Table Render Array Example Is Incorrect,!4848Issue #1566662: Update module should send notifications on Thursdays,!4792Issue #2230689: Remove redundant "Italic" style,!4220Issue #3368223: Link field > Access to internal links is not checked on display.,!3884Issue #3356842,!3870Issue #3087868,!3812Draft: Issue #3339373 by alexpott, andypost, mondrake:...,!3686Issue #3219967 against 9.5.x,!3683Issue #2939397: Clearing AliasManager cache with root path raises warning,!3543Issue #3344259: Allow ajax dialog to have focus configurable,!3356Issue #3209129: Scrolling problems when adding a block via layout builder,!2280Issue #3280415: Metapackage Generator Breaks Under Composer --no-dev,!2205Quote all names in the regions section.,!2050Issue #3272969: Remove UnqiueField constraint.,!1956Issue #3268872: hook_views_invalidate_cache not called when a view is deleted,!1893Issue #3217260: Add a way to make media captions not editable in CKEditor,!1459Issue #3087632: menu_name max length is too long,!878Issue #3221534: throw an exception when IDs passed to loadMultiple() are badly formed,!866Issue #2845319: The highlighting of the 'Home' menu-link does not respect query strings and fragment identifiers,!204Issue #3040556: It is not possible to react to an entity being duplicated
......@@ -22,6 +22,11 @@
*/
class TelephoneItem extends FieldItemBase {
/**
* The maximum length for a telephone value.
*/
const MAX_LENGTH = 256;
/**
* {@inheritdoc}
*/
......@@ -30,7 +35,7 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
'columns' => [
'value' => [
'type' => 'varchar',
'length' => 256,
'length' => self::MAX_LENGTH,
],
],
];
......@@ -62,12 +67,11 @@ public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$max_length = 256;
$constraints[] = $constraint_manager->create('ComplexData', [
'value' => [
'Length' => [
'max' => $max_length,
'maxMessage' => $this->t('%name: the telephone number may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]),
'max' => self::MAX_LENGTH,
'maxMessage' => $this->t('%name: the telephone number may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => self::MAX_LENGTH]),
],
],
]);
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\telephone\Plugin\Field\FieldType\TelephoneItem;
/**
* Plugin implementation of the 'telephone_default' widget.
......@@ -66,6 +67,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#type' => 'tel',
'#default_value' => $items[$delta]->value ?? NULL,
'#placeholder' => $this->getSetting('placeholder'),
'#maxlength' => TelephoneItem::MAX_LENGTH,
];
return $element;
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\telephone\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\telephone\Plugin\Field\FieldType\TelephoneItem;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -89,6 +90,7 @@ protected function setUp(): void {
public function testTelephoneWidget() {
$this->drupalGet('node/add/article');
$this->assertSession()->fieldValueEquals("field_telephone[0][value]", '');
$this->assertSession()->elementAttributeContains('css', 'input[name="field_telephone[0][value]"]', 'maxlength', TelephoneItem::MAX_LENGTH);
$this->assertSession()->responseContains('placeholder="123-456-7890"');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment