On entity forms that are not edit or delete, XML sitemap attempts to add its form fields and functionality, resulting in this errors similar to:

Warning: array_unshift() expects parameter 1 to be array, null given in xmlsitemap_add_form_link_options() (line 1256 of modules/contrib/xmlsitemap/xmlsitemap.module).
xmlsitemap_add_form_link_options(Array, 'node', 'test', '1983') (Line: 1580)
xmlsitemap_form_alter(Array, Object, 'node_test_entity_hierarchy_reorder_form') (Line: 539)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'node_test_entity_hierarchy_reorder_form') (Line: 834)
Drupal\Core\Form\FormBuilder->prepareForm('node_test_entity_hierarchy_reorder_form', Array, Object) (Line: 276)
Drupal\Core\Form\FormBuilder->buildForm('node_test_entity_hierarchy_reorder_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
...

The above error is from an entity form provided by Entity Hierarchy, but is also present for the entity form provided by Scheduled Transitions.

Fix is to make sure XML sitemap doesnt add its fields to forms that return NULL for \Drupal\Core\Form\BaseFormIdInterface::getBaseFormId (see docs).

Patch also changes order of conditions to reduce processing.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dpi created an issue. See original summary.

dpi’s picture

Issue summary: View changes
dpi’s picture

Assigned: dpi » Unassigned
Status: Active » Needs review
FileSize
1.3 KB

Status: Needs review » Needs work

The last submitted patch, 3: 3017153-xmlsitemap-forms.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rp7’s picture

Experiencing the same issue (when using Scheduled Transitions module) Patch in #3 fixed it for me.

Dave Reid’s picture

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
2.58 KB

I think this could be cleaned up a little bit more. We can get rid of xmlsitemap_form_controller() and do the logic all inline with xmlsitemap_form_alter().

Dave Reid’s picture

Tests expose that some entity types do not use an 'edit' operation, but use 'default' (why????).

Dave Reid’s picture

Little bit better logic.

  • Dave Reid committed 4198b5c on 8.x-1.x
    Issue #3017153 by Dave Reid, dpi: Fixed XML sitemap form fields should...
Dave Reid’s picture

Status: Needs review » Fixed

Committed #9 to 8.x-1.x. Thanks!

Status: Fixed » Closed (fixed)

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