When saving the block configuration with a non-default Theme hook suggestion, the following notice is displayed:

Notice: Undefined index: exists in Drupal\Core\Render\Element\MachineName::validateMachineName() (line 245 of core/lib/Drupal/Core/Render/Element/MachineName.php).
    Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in Drupal\Core\Render\Element\MachineName::validateMachineName() (line 246 of core/lib/Drupal/Core/Render/Element/MachineName.php).

To reproduce, add a menu block with (menu__)menu__level1 as theme hook suggestion.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan created an issue. See original summary.

Sutharsan’s picture

Issue tags: +Novice

Tagging as easy to fix.

Chalk’s picture

Assigned: Unassigned » Chalk

I've reproduced this issue. I will try fix it.

Chalk’s picture

Status: Active » Needs review
FileSize
940 bytes

Hi, @Sutharsan.
The problem is that a block plugin doesn't have an implementation of 'exists' function.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Ma...

As I understand, there is no need to validate theme hook suggestions by unique value. If I'm wrong - let me know and I will update the patch.

Sutharsan’s picture

Status: Needs review » Reviewed & tested by the community

Patch fixes the problem. Patch code is good. Doc with ::suggestionExists() answere my wtf question. Patch applies to latest dev. ::suggestionExists() must be public because it is called by MachineName::validateMachineName().

menu_block does not have unit tests :( so I assume it is Ok to RTBC a patch without tests. But correct me if I'm wrong.

Anonymous’s picture

Hi, I've tested this patch and it works. No longer getting the notice displaying when using a non-default theme hook suggestion. Could we get this merged in? Thanks, Jackie

iryston’s picture

Patch #4 fixes the problem. Thanks!

joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for resolving that @Chalk and @Sutharsan

  • joelpittet committed cc5fc51 on 8.x-1.x authored by Chalk
    Issue #2799991 by Chalk, Sutharsan: PHP notice 'Undefined index'
    

Status: Fixed » Closed (fixed)

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