From 7deb2b806524a198c4e050ba9c7ef179f06cfc1a Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Tue, 21 Apr 2020 13:09:20 -0600 Subject: [PATCH] Ensure we don't cause errors on create. --- .../ncit__private/ncit__private_widget.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/TripalFields/ncit__private/ncit__private_widget.inc b/includes/TripalFields/ncit__private/ncit__private_widget.inc index 15ddc22..cd2147b 100644 --- a/includes/TripalFields/ncit__private/ncit__private_widget.inc +++ b/includes/TripalFields/ncit__private/ncit__private_widget.inc @@ -72,9 +72,19 @@ class ncit__private_widget extends ChadoFieldWidget { */ public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) { $field_name = $this->instance['field_name']; - $entity_id = $form_state['TripalEntity']->id; $private = $form_state['values'][$field_name][$langcode][0]['is_private']; + // If this is a new entity (i.e. on create) + // then we can't access the entity_id here... + if (isset($form_state['TripalEntity']->is_new) AND ($form_state['TripalEntity']->is_new)) { + // We cannot set this entity to private on create so let the user know. + if ($private) { + drupal_set_message('Cannot set the page to private before it exists. Please edit the page to set it to private.', 'warning'); + } + return TRUE; + } + $entity_id = $form_state['TripalEntity']->id; + // If the user set this page to be public, remove our record for it. if (!$private) { db_query('DELETE FROM {private_biodata} WHERE entity_id=:id',