Commit d8776af5 authored by alexpott's avatar alexpott

Issue #2380391 by webflo: Fix storage settings for TextLongItem and StringLongItem

parent 826245d5
...@@ -91,14 +91,21 @@ public function getConstraints() { ...@@ -91,14 +91,21 @@ public function getConstraints() {
public static function generateSampleValue(FieldDefinitionInterface $field_definition) { public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$random = new Random(); $random = new Random();
$max = $field_definition->getSetting('max_length'); $max = $field_definition->getSetting('max_length');
$values['value'] = $random->word(mt_rand(1, $max));
if ($max) {
$values['value'] = $random->word(mt_rand(1, $max));
}
else {
$values['value'] = $random->paragraphs();
}
return $values; return $values;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = array(); $element = array();
$element['max_length'] = array( $element['max_length'] = array(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\Core\Field\Plugin\Field\FieldType; namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
/** /**
* Defines the 'string_long' field type. * Defines the 'string_long' field type.
...@@ -22,6 +23,15 @@ ...@@ -22,6 +23,15 @@
*/ */
class StringLongItem extends StringItem { class StringLongItem extends StringItem {
/**
* {@inheritdoc}
*/
public static function defaultStorageSettings() {
$settings = parent::defaultStorageSettings();
unset($settings['max_length']);
return $settings;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -36,4 +46,13 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) ...@@ -36,4 +46,13 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
); );
} }
/**
* {@inheritdoc}
*/
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = parent::storageSettingsForm($form, $form_state, $has_data);
unset($element['max_length']);
return $element;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment