summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-11-29 08:38:45 (GMT)
committerAlex Pott2014-11-29 08:38:45 (GMT)
commit1990524667ae216680e759c032c177844eaa5e4d (patch)
treeb294243df10d37a76bff38b82ebb12c7b537beeb
parent2f35d45dbbdc33b6c8cdbf1d1bbae29e3ca94de3 (diff)
Issue #2383277 by MrHaroldA: StringLongItem should not extend StringItem
-rw-r--r--core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php27
-rw-r--r--core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php32
-rw-r--r--core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php22
3 files changed, 41 insertions, 40 deletions
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 8641fa2..3f641e5 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php
@@ -10,10 +10,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Component\Utility\Random;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
-use Drupal\Core\Field\FieldItemBase;
-use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\TypedData\DataDefinition;
/**
* Defines the 'string' entity field type.
@@ -26,7 +23,7 @@ use Drupal\Core\TypedData\DataDefinition;
* default_formatter = "string"
* )
*/
-class StringItem extends FieldItemBase {
+class StringItem extends StringItemBase {
/**
* {@inheritdoc}
@@ -40,18 +37,6 @@ class StringItem extends FieldItemBase {
/**
* {@inheritdoc}
*/
- public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
- // This is called very early by the user entity roles field. Prevent
- // early t() calls by using the TranslationWrapper.
- $properties['value'] = DataDefinition::create('string')
- ->setLabel(new TranslationWrapper('Text value'));
-
- return $properties;
- }
-
- /**
- * {@inheritdoc}
- */
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
@@ -90,15 +75,7 @@ class StringItem extends FieldItemBase {
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$random = new Random();
- $max = $field_definition->getSetting('max_length');
-
- if ($max) {
- $values['value'] = $random->word(mt_rand(1, $max));
- }
- else {
- $values['value'] = $random->paragraphs();
- }
-
+ $values['value'] = $random->word(mt_rand(1, $field_definition->getSetting('max_length')));
return $values;
}
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php
new file mode 100644
index 0000000..c1ff41b
--- /dev/null
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Field\Plugin\Field\FieldType\StringItemBase.
+ */
+
+namespace Drupal\Core\Field\Plugin\Field\FieldType;
+
+use Drupal\Core\Field\FieldItemBase;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\StringTranslation\TranslationWrapper;
+use Drupal\Core\TypedData\DataDefinition;
+
+/**
+ * Base class for string field types.
+ */
+abstract class StringItemBase extends FieldItemBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
+ // This is called very early by the user entity roles field. Prevent
+ // early t() calls by using the TranslationWrapper.
+ $properties['value'] = DataDefinition::create('string')
+ ->setLabel(new TranslationWrapper('Text value'));
+
+ return $properties;
+ }
+
+}
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php
index 1a17ede..64f8690 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php
@@ -7,8 +7,9 @@
namespace Drupal\Core\Field\Plugin\Field\FieldType;
+use Drupal\Component\Utility\Random;
+use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
-use Drupal\Core\Form\FormStateInterface;
/**
* Defines the 'string_long' field type.
@@ -21,16 +22,7 @@ use Drupal\Core\Form\FormStateInterface;
* default_formatter = "string",
* )
*/
-class StringLongItem extends StringItem {
-
- /**
- * {@inheritdoc}
- */
- public static function defaultStorageSettings() {
- $settings = parent::defaultStorageSettings();
- unset($settings['max_length']);
- return $settings;
- }
+class StringLongItem extends StringItemBase {
/**
* {@inheritdoc}
@@ -49,10 +41,10 @@ class StringLongItem extends StringItem {
/**
* {@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;
+ public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
+ $random = new Random();
+ $values['value'] = $random->paragraphs();
+ return $values;
}
}