diff --git a/src/Plugin/Field/FieldWidget/MachineName.php b/src/Plugin/Field/FieldWidget/MachineName.php
index 46c7128..581851b 100644
--- a/src/Plugin/Field/FieldWidget/MachineName.php
+++ b/src/Plugin/Field/FieldWidget/MachineName.php
@@ -51,6 +51,9 @@ class MachineName extends WidgetBase {
       '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
       '#maxlength' => 64,
       '#disabled' => $disabled,
+      '#machine_name' => array(
+        'exists' => array($this, 'exists'),
+      )
     ];

     $element['value'] = $element + $widget;
@@ -83,4 +86,18 @@ class MachineName extends WidgetBase {
     return $summary;
   }

+  /**
+   * This method needs to exist, but the constrain does the actual validation.
+   *
+   * @param string $value
+   *   The input value.
+   *
+   * @return bool
+   *   As the MachineNameUnique constraint will do the actual validation, always
+   *   return FALSE to skip validation here.
+   */
+  public function exists($value) {
+    return FALSE;
+  }
+
 }

diff --git a/tests/src/Kernel/MachineNameItemTest.php b/tests/src/Kernel/MachineNameItemTest.php
new file mode 100644
index 0000000..8286ddb
--- /dev/null
+++ b/tests/src/Kernel/MachineNameItemTest.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Drupal\Tests\machine_name\Kernel;
+
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Field\FieldItemInterface;
+use Drupal\entity_test\Entity\EntityTest;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\Tests\field\Kernel\FieldKernelTestBase;
+use Drupal\field\Entity\FieldStorageConfig;
+
+/**
+ * Tests the new entity API for the machine_name field type.
+ *
+ * @group machine_name
+ */
+class MachineNameItemTest extends FieldKernelTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['machine_name'];
+
+  /**
+   * Sets the test up.
+   */
+  protected function setUp() {
+    parent::setUp();
+    // Create a machine_name field storage and field for validation.
+    FieldStorageConfig::create(array(
+      'field_name' => 'field_test',
+      'entity_type' => 'entity_test',
+      'type' => 'machine_name',
+    ))->save();
+    FieldConfig::create([
+      'entity_type' => 'entity_test',
+      'field_name' => 'field_test',
+      'bundle' => 'entity_test',
+    ])->save();
+
+  }
+
+  /**
+   * Tests using entity fields of the machine_name field type.
+   */
+  public function testTestItem() {
+    // Verify entity creation.
+    $entity = EntityTest::create();
+    $value = 'machine_name_test';
+    $entity->field_test = $value;
+    $entity->name->value = $this->randomMachineName();
+    $entity->save();
+
+    // Verify entity has been created properly.
+    $id = $entity->id();
+    $entity = EntityTest::load($id);
+    $this->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.');
+    $this->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
+    $this->assertEqual($entity->field_test->value, $value);
+    $this->assertEqual($entity->field_test[0]->value, $value);
+
+    // Verify changing the field value.
+    $new_value = 'changed_machine_name';
+    $entity->field_test->value = $new_value;
+    $this->assertEqual($entity->field_test->value, $new_value);
+
+    // Read changed entity and assert changed values.
+    $entity->save();
+    $entity = EntityTest::load($id);
+    $this->assertEqual($entity->field_test->value, $new_value);
+
+    // Test sample item generation.
+    $entity = EntityTest::create();
+    $entity->field_test->generateSampleItems();
+    $this->entityValidateAndSave($entity);
+  }
+}
