Loading tests/src/Functional/UniqueFieldAjaxBase.php +41 −2 Changes for tests/src/Functional/UniqueFieldAjaxBase.php: 41 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -86,6 +86,20 @@ class UniqueFieldAjaxBase extends BrowserTestBase { 'effect' => 'value', 'settings' => [], ], 'integer' => [ 'type' => 'integer', 'widget' => 'number', 'value' => 'integer', 'effect' => 'value', 'settings' => [], ], 'decimal' => [ 'type' => 'decimal', 'widget' => 'number', 'value' => 'decimal', 'effect' => 'value', 'settings' => [], ], ]; /** Loading Loading @@ -182,7 +196,11 @@ class UniqueFieldAjaxBase extends BrowserTestBase { * * @throws \Behat\Mink\Exception\ResponseTextException */ protected function itCanSaveField(array $edit, int $nid = NULL, bool $debug = FALSE): int { protected function itCanSaveField( array $edit, int $nid = NULL, bool $debug = FALSE ): int { $title = $edit['title[0][value]']; $method = $this->getSaveMethod($nid); $this->drupalPostForm($method, $edit, t('Save')); Loading Loading @@ -229,7 +247,11 @@ class UniqueFieldAjaxBase extends BrowserTestBase { * * @throws \Behat\Mink\Exception\ResponseTextException */ protected function itCanUpdateField(array $edit, int $nid, bool $debug = FALSE): int { protected function itCanUpdateField( array $edit, int $nid, bool $debug = FALSE ): int { return $this->itCanSaveField($edit, $nid, $debug); } Loading Loading @@ -408,6 +430,23 @@ class UniqueFieldAjaxBase extends BrowserTestBase { case 'email': $return = $this->createRandomData() . '@' . $this->createRandomData() . '.com'; break; case 'integer': try { $return = random_int(0, 9999); } catch (\Exception $e) { die('Could not generate random int'); } break; case 'decimal': $min = 0; $max = 9999; $decimals = 2; $scale = pow(10, $decimals); $return = mt_rand($min * $scale, $max * $scale) / $scale; break; } return $return; Loading unique_field_ajax.module +2 −1 Changes for unique_field_ajax.module: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -45,6 +45,8 @@ function unique_field_ajax_form_field_config_edit_form_alter(&$form, FormStateIn 'path', 'uri', 'link', 'integer', 'decimal', ]; if (!$field->getFieldStorageDefinition()->isMultiple()) { if (in_array($field->getType(), $unique_field_ajax_types)) { Loading Loading @@ -461,7 +463,6 @@ function unique_field_ajax_validate_unique($element, FormStateInterface $form_st * the entity that has the same value. */ function unique_field_ajax_is_unique($entity_type, $langcode, $field_name, $field_value, $bundle, $is_unique_per_lang, $entity) { $entity_type_definition = Drupal::entityTypeManager() ->getDefinition($entity_type); Loading Loading
tests/src/Functional/UniqueFieldAjaxBase.php +41 −2 Changes for tests/src/Functional/UniqueFieldAjaxBase.php: 41 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -86,6 +86,20 @@ class UniqueFieldAjaxBase extends BrowserTestBase { 'effect' => 'value', 'settings' => [], ], 'integer' => [ 'type' => 'integer', 'widget' => 'number', 'value' => 'integer', 'effect' => 'value', 'settings' => [], ], 'decimal' => [ 'type' => 'decimal', 'widget' => 'number', 'value' => 'decimal', 'effect' => 'value', 'settings' => [], ], ]; /** Loading Loading @@ -182,7 +196,11 @@ class UniqueFieldAjaxBase extends BrowserTestBase { * * @throws \Behat\Mink\Exception\ResponseTextException */ protected function itCanSaveField(array $edit, int $nid = NULL, bool $debug = FALSE): int { protected function itCanSaveField( array $edit, int $nid = NULL, bool $debug = FALSE ): int { $title = $edit['title[0][value]']; $method = $this->getSaveMethod($nid); $this->drupalPostForm($method, $edit, t('Save')); Loading Loading @@ -229,7 +247,11 @@ class UniqueFieldAjaxBase extends BrowserTestBase { * * @throws \Behat\Mink\Exception\ResponseTextException */ protected function itCanUpdateField(array $edit, int $nid, bool $debug = FALSE): int { protected function itCanUpdateField( array $edit, int $nid, bool $debug = FALSE ): int { return $this->itCanSaveField($edit, $nid, $debug); } Loading Loading @@ -408,6 +430,23 @@ class UniqueFieldAjaxBase extends BrowserTestBase { case 'email': $return = $this->createRandomData() . '@' . $this->createRandomData() . '.com'; break; case 'integer': try { $return = random_int(0, 9999); } catch (\Exception $e) { die('Could not generate random int'); } break; case 'decimal': $min = 0; $max = 9999; $decimals = 2; $scale = pow(10, $decimals); $return = mt_rand($min * $scale, $max * $scale) / $scale; break; } return $return; Loading
unique_field_ajax.module +2 −1 Changes for unique_field_ajax.module: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -45,6 +45,8 @@ function unique_field_ajax_form_field_config_edit_form_alter(&$form, FormStateIn 'path', 'uri', 'link', 'integer', 'decimal', ]; if (!$field->getFieldStorageDefinition()->isMultiple()) { if (in_array($field->getType(), $unique_field_ajax_types)) { Loading Loading @@ -461,7 +463,6 @@ function unique_field_ajax_validate_unique($element, FormStateInterface $form_st * the entity that has the same value. */ function unique_field_ajax_is_unique($entity_type, $langcode, $field_name, $field_value, $bundle, $is_unique_per_lang, $entity) { $entity_type_definition = Drupal::entityTypeManager() ->getDefinition($entity_type); Loading