Right now we have this in the code in the comment_notify_form_user_form_alter() method in the comment_notify.module file:

$user = $form_state->getFormObject()->getEntity();
$notify_settings = $user->id() ? comment_notify_get_user_notification_setting($user->id()) : comment_notify_get_default_notification_setting();

And in comment_notify_get_user_notification_setting() we have:

} else {
      $setting = db_select('comment_notify_user_settings', 'cnus')
        ->fields('cnus')
        ->condition('uid', $uid)
        ->execute()
        ->fetchObject();

      if (!$setting) {
        return NULL;
      }
      else {
        $users[$uid] = $setting;
      }

The problem is when the user hasn't a row in the comment_notify_user_settings table, this makes the function return NULL and $notify_settings is used later to determine the default values of the comment settngis fields.

I attach a small patch in my next comment and later I will try to provide a test.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gnuget created an issue. See original summary.

gnuget’s picture

Patch attached.

gnuget’s picture

Today I found an error with my first approach.

It seems to the NULL value on comment_notify_get_user_notification_setting() is expected in another part of the module so I revert that change and did the change directly on the comment_notify_form_user_form_alter() function.

patch attached.

DamienMcKenna’s picture

themic8’s picture

Hello,

Right now if I create or update a user I get this error:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Database\DatabaseExceptionWrapper</em>: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: &#039;&#039; for column &#039;node_notify&#039; at row 1: INSERT INTO {comment_notify_user_settings} (uid, node_notify, comment_notify) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array
(
    [:db_insert_placeholder_0] =&gt; 2554
    [:db_insert_placeholder_1] =&gt; 
    [:db_insert_placeholder_2] =&gt; none
)
 in <em class="placeholder">comment_notify_set_user_notification_setting()</em> (line <em class="placeholder">123</em> of <em class="placeholder">modules/comment_notify/comment_notify.inc</em>). <pre class="backtrace">Drupal\Core\Database\Statement-&gt;execute(Array, Array) (Line: 625)
Drupal\Core\Database\Connection-&gt;query(&#039;INSERT INTO {comment_notify_user_settings} (uid, node_notify, comment_notify) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2)&#039;, Array, Array) (Line: 87)
Drupal\Core\Database\Driver\mysql\Connection-&gt;query(&#039;INSERT INTO {comment_notify_user_settings} (uid, node_notify, comment_notify) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2)&#039;, Array, Array) (Line: 32)
Drupal\Core\Database\Driver\mysql\Insert-&gt;execute() (Line: 123)
comment_notify_set_user_notification_setting(&#039;2554&#039;, , &#039;none&#039;) (Line: 250)
_comment_notify_submit_user_form(Array, Object)
call_user_func_array(&#039;_comment_notify_submit_user_form&#039;, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter-&gt;executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter-&gt;doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder-&gt;processForm(&#039;user_form&#039;, Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder-&gt;buildForm(&#039;user_form&#039;, Object) (Line: 74)
Drupal\Core\Controller\FormController-&gt;getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 666)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>

I have also reviewed this table: comment_notify_user_settings which doesn't have any entries in it.

I'm still looking into it but wanted to put this out there.

  • greggles committed 2602dd4 on 8.x-1.x authored by gnuget
    Issue #2850935 by gnuget: Error when the user has been created and edit...
greggles’s picture

Status: Needs review » Fixed

Looks like a reasonable solution to me - thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.