Editing anything on my block views triggers the following logs:

Notice: Undefined index: allow in Drupal\ctools_views\Plugin\Display\Block->buildOptionsForm() (regel 50 van C:\xampp\htdocs\myproject\modules\ctools\modules\ctools_views\src\Plugin\Display\Block.php).
Notice: Undefined index: #default_value in Drupal\ctools_views\Plugin\Display\Block->buildOptionsForm() (regel 59 van C:\xampp\htdocs\myproject\modules\ctools\modules\ctools_views\src\Plugin\Display\Block.php).
Warning: array_filter() expects parameter 1 to be array, null given in Drupal\ctools_views\Plugin\Display\Block->buildOptionsForm() (regel 59 van C:\xampp\htdocs\myproject\modules\ctools\modules\ctools_views\src\Plugin\Display\Block.php).

Very simple view with the following settings:

  • Block
  • HTML-list
  • Teaser format
  • Filter: Publishing status (=Yes)
  • Filter: Content type (= Testimonials)
  • Relation: Entity Queue - Testimonials - required
  • Sort: Entity Queue - Position - Ascending
  • Pagination - limit to 5 items
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Joram created an issue. See original summary.

Joram’s picture

Issue summary: View changes
Joram’s picture

Title: Views fields not editable » Block.php notices and warnings
Issue summary: View changes
Joram’s picture

Priority: Critical » Normal
jzavrl’s picture

I got this as well, even with a very simple views block. After investigating I've seen that the function gets called when you are opening the options form for every section in the view config. Checked how the default core views block display plugin works and adjusted the code accordingly. Attached is a patch with the changes.

jzavrl’s picture

Status: Active » Needs review
FileSize
1.95 KB

Reattached to submit for testing.

darrenwh’s picture

Removed #5 file from view

japerry’s picture

HongPong’s picture

This is good but I had to add
if (isset($defaults)) {
$form['allow']['#default_value'] = $defaults;
}
after the switch. when i was trying to switch around 'pagerer' in block controls. Also had trouble applying patch. but got ahead with this (error was that $defaults was undefined after I applied the patch):

Status: Needs review » Needs work

The last submitted patch, 9: fixblockpager-2820783-9.patch, failed testing.

HongPong’s picture

Boo hoo trailing whitespace. deleted that line.

HongPong’s picture

Status: Needs work » Needs review
FileSize
2.06 KB

not sure why that didn't trigger tests. come on now.

Status: Needs review » Needs work

The last submitted patch, 12: fixblockpager-2820783-11.patch, failed testing.

jzavrl’s picture

Not sure that's the correct play there. The $defaults are only being set inside the switch statement, so there might be a better way to do this. What were the steps to reproduce your issue?

HongPong’s picture

jzavrl I have not had time to reproduce this, but it was a view with a block and a page. I couldn't get to the view's pager controls popup on the block display ( to switch the pager off, as it was turned on) without getting back ajax 500 errors like those above. Being unclear on the nature of the function I just kept the isset as a separate statement from the switch, but yes I bet they could go together. Just conveying how the patch helped me get around the fatal error successfully, and save the results from the popup.

darrenwh’s picture

+++ b/modules/ctools/modules/ctools_views/src/Plugin/Display/Block.php
@@ -47,20 +47,26 @@ public function optionsSummary(&$categories, &$options) {
+        $options['offset'] = $this->t('Pager offset');
+        $options['pager'] = $this->t('Pager type');

Could this array declaration be set out as per DCS https://www.drupal.org/docs/develop/standards/coding-standards#array
Somthing like:

$options = array(
'offset' => $this->t('Pager offset'),
'pager' =>$this->t('Pager type'), ...

Then

 $form['allow']['#options'] = $form['allow']['#options'] + $options;
DamienMcKenna’s picture

DamienMcKenna’s picture

Lets bump this so that beta2 can be rolled out.

T-lo’s picture

Assigned: Unassigned » T-lo
darrenwh’s picture

Tidy up

T-lo’s picture

This was blocking me today so here's a re-roll and an update:

Changed the array declaration as per suggestion by @darrenwh, and as $form['allow']['#options'] is fully overwritten anyway.

T-lo’s picture

Status: Needs work » Needs review
T-lo’s picture

Assigned: T-lo » Unassigned

The last submitted patch, 21: fixblockpager-2820783-21.patch, failed testing.

T-lo’s picture

Passed testing second time around, seems to have been an issue with the test server

darrenwh’s picture

Status: Needs review » Needs work
+++ b/modules/ctools_views/src/Plugin/Display/Block.php
@@ -43,20 +43,26 @@ class Block extends CoreBlock {
+         'offset' => $this->t('Pager offset'),

The indentation is slightly off here

The interdiff is giving an error when previewed (Unexpected request?)

T-lo’s picture

Assigned: Unassigned » T-lo
T-lo’s picture

Assigned: T-lo » Unassigned
Status: Needs work » Needs review
FileSize
1.9 KB
3.63 KB

Indentation fixed and new interdiff created.

me5h’s picture

Status: Needs review » Reviewed & tested by the community

Tested in preproduction and is working as expected.

rvanderh1’s picture

I'm also getting this error:

Notice: Undefined index: allow in Drupal\ctools_views\Plugin\Display\Block->buildOptionsForm() (line 46...

Whenever I go to edit a block view, even though I'm using ctools 8.x-3.0+3-dev (dated 11 July 2017).

T-lo’s picture

@rvanderh1 This fix hasn't been committed yet, apply the patch in comment #28 and it should resolve the issue.

rvanderh1’s picture

OK, thanks. The patch resolved the issue. When do you think the fix will be committed?

mattlt’s picture

Patch fixed multiple issues we were having with ajax and editing multiple options inside a block view.

Thanks,

•• matt

Christopher Riley’s picture

Patched fixed multiple issues for me as well I will be glad when this is committed.

adriancid’s picture

+1 RTBC for me too.

DuneBL’s picture

#28 solve my problem too...

sneo’s picture

#28 solve it for me too, would be great if this could be up soon :D

markpavlitski’s picture

+1 for RTBC. Patch applies cleanly and fixes a number of interface issues.

joelpittet’s picture

Status: Reviewed & tested by the community » Needs review

Thanks for testing this out, I'm looking to commit this but want to check on a small thing.

+++ b/modules/ctools_views/src/Plugin/Display/Block.php
@@ -43,20 +43,26 @@ class Block extends CoreBlock {
+    switch ($form_state->get('section')) {
+      case 'allow':

nit: this should likely be a an if statement don't you think, or is there plans to break off other section's?

T-lo’s picture

Assigned: Unassigned » T-lo
Status: Needs review » Needs work
T-lo’s picture

FileSize
1.84 KB
1.76 KB

@joelpittet good point, I've swapped that for an if statement. If other sections need breaking out in the future, a switch can be implemented then.

T-lo’s picture

Assigned: T-lo » Unassigned
Status: Needs work » Needs review
Renrhaf’s picture

Patch from #41 fixed the issue for me (Drupal 8.6.1)

mattlt’s picture

Hello,

Patch from #41 no longer applies cleanly due to this similar issue that was recently committed…

https://www.drupal.org/node/2978750

Thanks,

•• matt

joelpittet’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Ah didn't see they were touching, this needs a reroll.

suit4’s picture

Same here, got ajax error undefined index: allow in Drupal\ctools views\Plugin\Display\Block->buildOptionsForm() ...

#41 seems to fix the issue, if Block.php is unpatched.

suit4’s picture

Tried to build a combined patch.

thalles’s picture

Status: Needs work » Needs review
FileSize
1.58 KB

Follow the patch!

joelpittet’s picture

+++ b/modules/ctools_views/src/Plugin/Display/Block.php
@@ -41,19 +41,19 @@ class Block extends CoreBlock {
-      if (!empty($defaults['items_per_page'])) {
+      if (isset($defaults['items_per_page']) && !empty($defaults['items_per_page'])) {

!empty() does an implicit isset(), so calling isset() before !empty() is a bit redundant.

I've lost track what this patch is fixing, can anybody tell me?

thalles’s picture

You're right!

On php.net

"empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set."

So essentially

<?php
if (isset($var) && $var)
?>

is the same as

<?php
if (!empty($var))
?>

doesn't it? :)

!empty() mimics the chk() function posted before.

thalles’s picture

joelpittet’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll

I could see how this could still produce a warning and notice and the patch doesn't seem to fix that possiblitity.

This code $options = $form['allow']['#options']; before copied the allow options passed in (when they exist) and the new code
$form['allow']['#options'] = [...] clobbers any options that are passed in already.

The original issue is Notice: Undefined index: allow

So we could just set those values individually:
$form['allow']['#options']['offset'] = $this->t('Pager offset');

thalles’s picture

Status: Needs work » Needs review
FileSize
1.48 KB

Follow!

joelpittet’s picture

Status: Needs review » Postponed (maintainer needs more info)

@thalles and I can't seem to find where this original notice stems from. Could someone help by letting us know where or at least running across this issue and letting us know if the patch in #53 resolves it?

Thanks for the patch @thalles!

AnaSwin’s picture

Patch worked for me (Drupal 8.6.10, PHP 7.2) Thx :)

thalles’s picture

How can I test?

seros-me’s picture

Patch worked for me too!!

Thanks for the patch @thalles!

Drupal 8.6.10, PHP 7.2

thalles’s picture

@seros-me, how can I test?

HongPong’s picture

@thalles in my case, originally, with "pagerer" module enabled, and a block set to be paginated, i could trigger the error by attempting to disable the pager. Attached to a view was a block and a page. Inside Views UI: I couldn't get to the view's pager controls popup on the block display ( to switch the pager off, as it was turned on) without getting back ajax 500 errors like those above.

thalles’s picture

@HongPong, after the patch the bug has been fixed?

thalles’s picture

Status: Postponed (maintainer needs more info) » Needs review
joelpittet’s picture

Title: Block.php notices and warnings » Block.php Undefined index: allow
Status: Needs review » Fixed

Ideally it would be nice to know "what" was fixed with this patch but I could imagine. Thanks for helping @thalles, I've committed this to the latest dev release.

  • joelpittet committed f954ed7 on 8.x-3.x authored by thalles
    Issue #2820783 by T-lo, thalles, HongPong, jzavrl, suit4, joelpittet,...
thalles’s picture

Thanks @joelpittet!
Thanks all!

Status: Fixed » Closed (fixed)

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

eblue’s picture

I'm still experiencing this issue as referenced in https://www.drupal.org/project/ctools/issues/3038160. I only get the AJAX error on new views I create on my local, not ones from core.

Undefined index: allow in /Users/digitalechidna/Sites/caaspr/docroot/modules/contrib/ctools/modules/ctools_views/src/Plugin/Display/Block.php on line 57

T-lo’s picture

@eblue this was committed after the most recent release, so it's only fixed in the development branch currently.
You can apply the patch above to fix the issue until there's a new release