Commit aed35d3a authored by webchick's avatar webchick

Issue #2218199 by andypost: Move email and number field types to...

Issue #2218199 by andypost: Move email and number field types to \Drupal\Core\Field, remove modules.
parent caad3b80
......@@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\number\Plugin\field\formatter\NumberDecimalFormatter.
* Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\DecimalFormatter.
*/
namespace Drupal\number\Plugin\Field\FieldFormatter;
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
/**
* Plugin implementation of the 'number_decimal' formatter.
......@@ -18,8 +18,8 @@
* id = "number_decimal",
* label = @Translation("Default"),
* field_types = {
* "number_decimal",
* "number_float"
* "decimal",
* "float"
* },
* settings = {
* "thousand_separator" = "",
......@@ -29,7 +29,7 @@
* }
* )
*/
class NumberDecimalFormatter extends DefaultNumberFormatter {
class DecimalFormatter extends NumericFormatterBase {
/**
* {@inheritdoc}
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\number\Plugin\field\formatter\NumberIntegerFormatter.
* Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\IntegerFormatter.
*/
namespace Drupal\number\Plugin\Field\FieldFormatter;
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
/**
* Plugin implementation of the 'number_integer' formatter.
......@@ -18,7 +18,7 @@
* id = "number_integer",
* label = @Translation("Default"),
* field_types = {
* "number_integer"
* "integer"
* },
* settings = {
* "thousand_separator" = "",
......@@ -26,7 +26,7 @@
* }
* )
*/
class NumberIntegerFormatter extends DefaultNumberFormatter {
class IntegerFormatter extends NumericFormatterBase {
/**
* {@inheritdoc}
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\email\Plugin\Field\FieldFormatter\MailToFormatter.
* Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\MailToFormatter.
*/
namespace Drupal\email\Plugin\Field\FieldFormatter;
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
......
......@@ -2,18 +2,18 @@
/**
* @file
* Contains \Drupal\number\Plugin\field\formatter\DefaultNumberFormatter.
* Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericFormatterBase.
*/
namespace Drupal\number\Plugin\Field\FieldFormatter;
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Parent plugin for decimal and integer formatters
* Parent plugin for decimal and integer formatters.
*/
abstract class DefaultNumberFormatter extends FormatterBase {
abstract class NumericFormatterBase extends FormatterBase {
/**
* {@inheritdoc}
......@@ -94,4 +94,5 @@ public function viewElements(FieldItemListInterface $items) {
* The formatted number.
*/
abstract protected function numberFormat($number);
}
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\number\Plugin\field\formatter\NumberUnformattedFormatter.
* Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericUnformattedFormatter.
*/
namespace Drupal\number\Plugin\Field\FieldFormatter;
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
......@@ -17,13 +17,13 @@
* id = "number_unformatted",
* label = @Translation("Unformatted"),
* field_types = {
* "number_integer",
* "number_decimal",
* "number_float"
* "integer",
* "decimal",
* "float"
* }
* )
*/
class NumberUnformattedFormatter extends FormatterBase {
class NumericUnformattedFormatter extends FormatterBase {
/**
* {@inheritdoc}
......
......@@ -2,19 +2,19 @@
/**
* @file
* Contains \Drupal\number\Plugin\Field\FieldType\DecimalItem.
* Contains \Drupal\Core\Field\Plugin\Field\FieldType\DecimalItem.
*/
namespace Drupal\number\Plugin\Field\FieldType;
namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
/**
* Plugin implementation of the 'number_decimal' field type.
* Defines the 'decimal' field type.
*
* @FieldType(
* id = "number_decimal",
* id = "decimal",
* label = @Translation("Number (decimal)"),
* description = @Translation("This field stores a number in the database in a fixed decimal format."),
* settings = {
......@@ -31,7 +31,7 @@
* default_formatter = "number_decimal"
* )
*/
class DecimalItem extends NumberItemBase {
class DecimalItem extends NumericItemBase {
/**
* {@inheritdoc}
......@@ -51,8 +51,8 @@ public static function schema(FieldDefinitionInterface $field_definition) {
'columns' => array(
'value' => array(
'type' => 'numeric',
'precision' => $field_definition->settings['precision'],
'scale' => $field_definition->settings['scale'],
'precision' => $field_definition->getSetting('precision'),
'scale' => $field_definition->getSetting('scale'),
'not null' => FALSE
)
),
......
......@@ -12,14 +12,13 @@
use Drupal\Core\TypedData\DataDefinition;
/**
* Defines the 'email' entity field type.
* Defines the 'email' field type.
*
* @FieldType(
* id = "email",
* label = @Translation("E-mail"),
* description = @Translation("An entity field containing an e-mail value."),
* configurable = FALSE,
* default_widget = "string",
* default_widget = "email_default",
* default_formatter = "string"
* )
*/
......
......@@ -2,26 +2,32 @@
/**
* @file
* Contains \Drupal\Core\Entity\Plugin\Field\FieldType\FloatItem.
* Contains \Drupal\Core\Field\Plugin\Field\FieldType\FloatItem.
*/
namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\TypedData\DataDefinition;
/**
* Defines the 'float' entity field type.
* Defines the 'float' field type.
*
* @FieldType(
* id = "float",
* label = @Translation("Float"),
* description = @Translation("An entity field containing an float value."),
* configurable = FALSE
* label = @Translation("Number (float)"),
* description = @Translation("This field stores a number in the database in a floating point format."),
* instance_settings = {
* "min" = "",
* "max" = "",
* "prefix" = "",
* "suffix" = ""
* },
* default_widget = "number",
* default_formatter = "number_decimal"
* )
*/
class FloatItem extends FieldItemBase {
class FloatItem extends NumericItemBase {
/**
* {@inheritdoc}
......
......@@ -2,26 +2,32 @@
/**
* @file
* Contains \Drupal\Core\Entity\Plugin\Field\FieldType\IntegerItem.
* Contains \Drupal\Core\Field\Plugin\Field\FieldType\IntegerItem.
*/
namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\TypedData\DataDefinition;
/**
* Defines the 'integer' entity field type.
* Defines the 'integer' field type.
*
* @FieldType(
* id = "integer",
* label = @Translation("Integer"),
* description = @Translation("An entity field containing an integer value."),
* configurable = FALSE
* label = @Translation("Number (integer)"),
* description = @Translation("This field stores a number in the database as an integer."),
* instance_settings = {
* "min" = "",
* "max" = "",
* "prefix" = "",
* "suffix" = ""
* },
* default_widget = "number",
* default_formatter = "number_integer"
* )
*/
class IntegerItem extends FieldItemBase {
class IntegerItem extends NumericItemBase {
/**
* {@inheritdoc}
......@@ -41,7 +47,7 @@ public static function schema(FieldDefinitionInterface $field_definition) {
'columns' => array(
'value' => array(
'type' => 'int',
'not null' => TRUE,
'not null' => FALSE,
),
),
);
......
......@@ -2,17 +2,17 @@
/**
* @file
* Contains \Drupal\number\Plugin\Field\FieldType\NumberItemBase.
* Contains \Drupal\Core\Field\Plugin\Field\FieldType\NumericItemBase.
*/
namespace Drupal\number\Plugin\Field\FieldType;
namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
/**
* Base class for 'number' configurable field types.
* Base class for numeric configurable field types.
*/
abstract class NumberItemBase extends FieldItemBase {
abstract class NumericItemBase extends FieldItemBase {
/**
* {@inheritdoc}
......
......@@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\email\Plugin\Field\FieldWidget\EmailDefaultWidget.
* Contains \Drupal\Core\Field\Plugin\Field\FieldWidget\EmailDefaultWidget.
*/
namespace Drupal\email\Plugin\Field\FieldWidget;
namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\number\Plugin\Field\FieldWidget\NumberWidget.
* Contains \Drupal\Core\Field\Plugin\Field\FieldWidget\NumberWidget.
*/
namespace Drupal\number\Plugin\Field\FieldWidget;
namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
......@@ -18,9 +18,9 @@
* id = "number",
* label = @Translation("Text field"),
* field_types = {
* "number_integer",
* "number_decimal",
* "number_float"
* "integer",
* "decimal",
* "float"
* },
* settings = {
* "placeholder" = ""
......@@ -74,11 +74,11 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
// Set the step for floating point and decimal numbers.
switch ($this->fieldDefinition->getType()) {
case 'number_decimal':
case 'decimal':
$element['#step'] = pow(0.1, $field_settings['scale']);
break;
case 'number_float':
case 'float':
$element['#step'] = 'any';
break;
}
......
......@@ -17,8 +17,7 @@
* id = "string",
* label = @Translation("String field"),
* field_types = {
* "string",
* "email"
* "string"
* },
* settings = {
* "size" = "60",
......
......@@ -19,7 +19,7 @@ class EditTestBase extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('system', 'entity', 'entity_test', 'field', 'field_test', 'number', 'filter', 'user', 'text', 'edit');
public static $modules = array('system', 'entity', 'entity_test', 'field', 'field_test', 'filter', 'user', 'text', 'edit');
/**
* Sets the default field storage backend for fields created during tests.
......
......@@ -153,7 +153,7 @@ public function testTextWysiwyg() {
public function testNumber() {
$field_name = 'field_nr';
$this->createFieldWithInstance(
$field_name, 'number_integer', 1, 'Simple number field',
$field_name, 'integer', 1, 'Simple number field',
// Instance settings.
array(),
// Widget type & settings.
......
......@@ -83,7 +83,7 @@ public function testSimpleEntityType() {
$field_2_name = 'field_nr';
$field_2_label = 'Simple number field';
$this->createFieldWithInstance(
$field_2_name, 'number_integer', 1, $field_2_label,
$field_2_name, 'integer', 1, $field_2_label,
// Instance settings.
array(),
// Widget type & settings.
......
# Schema for the configuration files of the Email module.
field.email.settings:
type: sequence
label: 'E-mail settings'
sequence:
- type: string
field.email.instance_settings:
type: sequence
label: 'E-mail settings'
sequence:
- type: string
label: 'Setting'
field.email.value:
type: sequence
label: 'Default value'
sequence:
- type: mapping
label: 'Default'
mapping:
value:
type: email
label: 'Value'
name: E-mail
type: module
description: 'Defines a field type for e-mail addresses.'
package: Field types
version: VERSION
core: 8.x
dependencies:
- field
<?php
/**
* @file
* Defines a simple e-mail field type.
*/
/**
* Implements hook_help().
*/
function email_help($path, $arg) {
switch ($path) {
case 'admin/help#email':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The E-mail module allows you to create fields that contain e-mail addresses. See the <a href="@field">Field module help</a> and the <a href="@field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href="@email_documentation">online documentation for the E-mail module</a>.', array('@field' => url('admin/help/field'), '@field_ui' => url('admin/help/field_ui'), '@email_documentation' => 'https://drupal.org/documentation/modules/email')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Managing and displaying email fields') . '</dt>';
$output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the email field can be configured separately. See the <a href="@field_ui">Field UI help</a> for more information on how to manage fields and their display.', array('@field_ui' => url('admin/help/field_ui'))) . '</dd>';
$output .= '<dt>' . t('Displaying e-mail addresses as links') . '</dt>';
$output .= '<dd>' . t('E-mail addresses can be displayed as <em>plain text</em> or as <em>links</em> by choosing the appropriate display format.') . '</dd>';
$output .= '<dt>' . t('Validating E-mail addresses') . '</dt>';
$output .= '<dd>' . t('E-mail addresses are validated when the content is saved.') . '</dd>';
$output .= '</dl>';
return $output;
}
}
/**
* Implements hook_field_info_alter().
*/
function email_field_info_alter(&$info) {
$info['email']['configurable'] = TRUE;
$info['email']['default_widget'] = 'email_default';
$info['email']['provider'] = 'email';
}
......@@ -115,3 +115,197 @@ entity_form_display.field.hidden:
sequence:
- type: string
# Schema for the configuration files of the Email field type.
field.email.settings:
type: sequence
label: 'E-mail settings'
sequence:
- type: string
field.email.instance_settings:
type: sequence
label: 'E-mail settings'
sequence:
- type: string
label: 'Setting'
field.email.value:
type: sequence
label: 'Default value'
sequence:
- type: mapping
label: 'Default'
mapping:
value:
type: email
label: 'Value'
# Schema for configuration files of a numeric field types.
field.integer.settings:
type: sequence
label: 'Integer settings'
sequence:
- type: string
label: 'setting'
field.integer.instance_settings:
type: mapping
label: 'Integer'
mapping:
min:
type: integer
label: 'Minimum'
max:
type: integer
label: 'Maximum'
prefix:
type: string
label: 'Prefix'
suffix:
type: string
label: 'Suffix'
field.integer.value:
type: sequence
label: 'Default value'
sequence:
- type: mapping
label: 'Default value'
mapping:
value:
type: integer
label: 'Value'
field.decimal.settings:
type: mapping
label: 'Decimal settings'
mapping:
precision:
type: integer
label: 'Precision'
scale:
type: integer
label: 'Scale'
field.decimal.instance_settings:
type: mapping
label: 'Decimal'
mapping:
min:
type: float
label: 'Minimum'
max:
type: float
label: 'Maximum'
prefix:
type: string
label: 'Prefix'
suffix:
type: string
label: 'Suffix'
field.decimal.value:
type: sequence
label: 'Default value'
sequence:
- type: mapping
label: 'Default value'
mapping:
value:
type: float
label: 'Value'
field.float.settings:
type: sequence
label: 'Float settings'
sequence:
- type: string
label: 'setting'
field.float.instance_settings:
type: mapping
label: 'Float'
mapping:
min:
type: float
label: 'Minimum'
max:
type: float
label: 'Maximum'
prefix:
type: string
label: 'Prefix'
suffix:
type: string
label: 'Suffix'
field.float.value:
type: sequence
label: 'Default value'
sequence:
- type: mapping
label: 'Default value'
mapping:
value:
type: float
label: 'Value'
entity_view_display.field.number_decimal:
type: entity_field_view_display_base
label: 'Number decimal display format settings'
mapping:
settings:
type: mapping
label: 'Settings'
mapping:
thousand_separator:
type: string
label: 'Thousand marker'
decimal_separator:
type: string
label: 'Decimal marker'
scale:
type: integer
label: 'Scale'
prefix_suffix:
type: boolean
label: 'Display prefix and suffix.'
entity_view_display.field.number_integer:
type: entity_field_view_display_base
label: 'Number interger display format settings'
mapping:
settings:
type: mapping
label: 'Settings'
mapping:
thousand_separator:
type: string
label: 'Thousand marker'
prefix_suffix:
type: boolean
label: 'Display prefix and suffix.'
entity_view_display.field.number_unformatted:
type: entity_field_view_display_base
label: 'Number unformatted display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_form_display.field.number:
type: entity_field_form_display_base
label: 'Number default display format settings'
mapping:
settings:
type: mapping
label: 'Settings'
mapping:
placeholder:
type: label
label: 'Placeholder'
......@@ -75,7 +75,7 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
/**
* The field type.
*
* Example: text, number_integer.
* Example: text, integer.
*
* @var string
*/
......
......@@ -135,7 +135,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
*
* This property is overlooked if the $default_value_function is non-empty.
*
* Example for a number_integer field:
* Example for a integer field:
* @code
* array(
* array('value' => 1),
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\field\Tests\CrudTest.
* Contains \Drupal\field\Tests\CrudTest.
*/
namespace Drupal\field\Tests;
......@@ -17,7 +17,7 @@ class CrudTest extends FieldUnitTestBase {