diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php index ec49cdb..4938c48 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php @@ -18,7 +18,10 @@ * id = "integer", * label = @Translation("Integer"), * description = @Translation("An entity field containing an integer value."), - * configurable = FALSE + * configurable = FALSE, + * settings = { + * "unsigned" = FALSE, + * }, * ) */ class IntegerItem extends FieldItemBase { @@ -47,12 +50,30 @@ public function getPropertyDefinitions() { /** * {@inheritdoc} */ + public function getConstraints() { + $constraints = parent::getConstraints(); + + // If this is an unsigned integer, add a validation constraint for the + // integer to be positive. + if ($this->getFieldSetting('unsigned')) { + $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager(); + $constraints[] = $constraint_manager->create('Range', array('min' => 0)); + } + + return $constraints; + } + + /** + * {@inheritdoc} + */ public static function schema(FieldDefinitionInterface $field_definition) { return array( 'columns' => array( 'value' => array( 'type' => 'int', 'not null' => TRUE, + // Expose the 'unsigned' setting in the field item schema. + 'unsigned' => (bool) $field_definition->getSetting('unsigned'), ), ), ); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php index 61eae79..3ae5b1f 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php @@ -125,7 +125,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['fid'] = FieldDefinition::create('integer') ->setLabel(t('Feed ID')) ->setDescription(t('The ID of the aggregator feed.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) @@ -146,7 +147,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['refresh'] = FieldDefinition::create('integer') ->setLabel(t('Refresh')) - ->setDescription(t('How often to check for new feed items, in seconds.')); + ->setDescription(t('How often to check for new feed items, in seconds.')) + ->setSetting('unsigned', TRUE); // @todo Convert to a "timestamp" field in https://drupal.org/node/2145103. $fields['checked'] = FieldDefinition::create('integer') diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php index e48e45d9..509265b 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php @@ -64,7 +64,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['iid'] = FieldDefinition::create('integer') ->setLabel(t('Aggregator item ID')) ->setDescription(t('The ID of the feed item.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['fid'] = FieldDefinition::create('entity_reference') ->setLabel(t('Aggregator feed ID')) diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php index 68c3b10..bf9e6b8 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php @@ -168,7 +168,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['id'] = FieldDefinition::create('integer') ->setLabel(t('Custom block ID')) ->setDescription(t('The custom block ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) @@ -178,7 +179,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['revision_id'] = FieldDefinition::create('integer') ->setLabel(t('Revision ID')) ->setDescription(t('The revision ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['langcode'] = FieldDefinition::create('language') ->setLabel(t('Language code')) diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 9732c91..8ca780e 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -356,7 +356,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['cid'] = FieldDefinition::create('integer') ->setLabel(t('Comment ID')) ->setDescription(t('The comment ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index 816435b..e880102 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -228,7 +228,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['fid'] = FieldDefinition::create('integer') ->setLabel(t('File ID')) ->setDescription(t('The file ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) @@ -258,7 +259,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['filesize'] = FieldDefinition::create('integer') ->setLabel(t('File size')) - ->setDescription(t('The size of the file in bytes.')); + ->setDescription(t('The size of the file in bytes.')) + ->setSetting('unsigned', TRUE); $fields['status'] = FieldDefinition::create('integer') ->setLabel(t('Status')) diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index ec3533a..91c98f3 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -348,7 +348,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['nid'] = FieldDefinition::create('integer') ->setLabel(t('Node ID')) ->setDescription(t('The node ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) @@ -358,7 +359,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['vid'] = FieldDefinition::create('integer') ->setLabel(t('Revision ID')) ->setDescription(t('The node revision ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['type'] = FieldDefinition::create('entity_reference') ->setLabel(t('Type')) diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php index 7b2017b..75726b9 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php @@ -138,7 +138,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['id'] = FieldDefinition::create('integer') ->setLabel(t('ID')) ->setDescription(t('The ID of the shortcut.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index b33285c..ea8f520 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -235,6 +235,7 @@ function testEntityQuery() { // word but allows us to test revisions and string operations. $ids = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'merhaba') + ->sort('id') ->execute(); $entities = entity_load_multiple('entity_test_mulrev', $ids); foreach ($entities as $entity) { @@ -267,12 +268,14 @@ function testEntityQuery() { $this->assertIdentical($results, $assert); $results = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'siema', 'STARTS_WITH') + ->sort('revision_id') ->execute(); // Now we only get the ones that originally were siema, entity id 8 and // above. $this->assertIdentical($results, array_slice($assert, 4, 8, TRUE)); $results = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'a', 'ENDS_WITH') + ->sort('revision_id') ->execute(); // It is very important that we do not get the ones which only have // xsiemax despite originally they were merhaba, ie. ended with a. diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php index b7f799c..8431eae 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php @@ -127,7 +127,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['id'] = FieldDefinition::create('integer') ->setLabel(t('ID')) ->setDescription(t('The ID of the test entity.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php index e0dce68..a73b08d 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php @@ -53,7 +53,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['revision_id'] = FieldDefinition::create('integer') ->setLabel(t('Revision ID')) ->setDescription(t('The version id of the test entity.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['default_langcode'] = FieldDefinition::create('boolean') ->setLabel(t('Default language')) diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php index a31dcdc..29e2a13 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php @@ -72,7 +72,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['revision_id'] = FieldDefinition::create('integer') ->setLabel(t('Revision ID')) ->setDescription(t('The version id of the test entity.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); return $fields; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php index 32e0e9c..539e4d0 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php @@ -201,7 +201,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['tid'] = FieldDefinition::create('integer') ->setLabel(t('Term ID')) ->setDescription(t('The term ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID')) @@ -235,7 +236,8 @@ public static function baseFieldDefinitions($entity_type) { ->setDescription(t('The parents of this term.')) // Save new terms with no parents by default. ->setSetting('default_value', 0) - ->setComputed(TRUE); + ->setComputed(TRUE) + ->setSetting('unsigned', TRUE); $fields['changed'] = FieldDefinition::create('integer') ->setLabel(t('Changed')) diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index f9db482..8a2f577 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -427,7 +427,8 @@ public static function baseFieldDefinitions($entity_type) { $fields['uid'] = FieldDefinition::create('integer') ->setLabel(t('User ID')) ->setDescription(t('The user ID.')) - ->setReadOnly(TRUE); + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); $fields['uuid'] = FieldDefinition::create('uuid') ->setLabel(t('UUID'))