From 220b7b81b0c1da547ce7dff87e8fd7a6d245d9bd Mon Sep 17 00:00:00 2001
From: Yousef Bajawi <jose@josebcdev.com>
Date: Tue, 30 Jan 2018 16:45:08 +0200
Subject: [PATCH] Issue 2916257: cannot set table fields as not null.

---
 src/Entity/TableConfig.php   |  2 ++
 src/Form/TableConfigForm.php | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/src/Entity/TableConfig.php b/src/Entity/TableConfig.php
index 443dc6d..e8d6e0b 100644
--- a/src/Entity/TableConfig.php
+++ b/src/Entity/TableConfig.php
@@ -65,12 +65,14 @@ class TableConfig extends ConfigEntityBase implements TableConfigInterface {
         'type' => $field['type'],
         'size' => $field['size'],
         'unsigned' => $field['unsigned'],
+        'not null' => $field['not_null'],
       );
       if ($field['length']) {
         $table_definition['fields'][$field['name']]['length'] = $field['length'];
       }
       if ($field['primary']) {
         $primary_keys[] = $field['name'];
+        $table_definition['fields'][$field['name']]['not null'] = TRUE;
       }
     }
     // @todo: non-primary index definition.
diff --git a/src/Form/TableConfigForm.php b/src/Form/TableConfigForm.php
index 3a5c418..2a0539a 100644
--- a/src/Form/TableConfigForm.php
+++ b/src/Form/TableConfigForm.php
@@ -75,6 +75,7 @@ class TableConfigForm extends EntityForm {
           t('Size'),
           t('Length'),
           t('Unsigned'),
+          t('Not null'),
           t('Index'),
           t('Primary key'),
         ),
@@ -161,6 +162,7 @@ class TableConfigForm extends EntityForm {
       'size',
       'length',
       'unsigned',
+      'not_null',
       'index',
       'primary',
     ), '');
@@ -205,6 +207,15 @@ class TableConfigForm extends EntityForm {
       '#type' => 'checkbox',
       '#default_value' => $current['unsigned'],
     );
+    $form['not_null'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => $current['not_null'],
+      '#states' => [
+        'checked' => [
+          ["#edit-table-schema-$index-primary" => ['checked' => TRUE]],
+        ],
+      ],
+    );
     $form['index'] = array(
       '#type' => 'checkbox',
       '#default_value' => $current['index'],
-- 
2.7.4

