in scheduler_form_node_form_alter we are doing more processing than is necessary - if neither scheduled publishing nor scheduled unpiublishing are enabled we can exit out of the function at an early stage. Currently there is no return so the entire function is processed. The only way that the fields are not actually displayed on the form is when #access is set to false (for either or both). There is only one small block which has a conditional test on whether scheduling is enabled.

It will be better to check this further up the function and exit early if nothing is needed.

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

Title: Remove unnecessary processing in hook_node_form_alter » Exit early to avoid unnecessary processing in hook_node_form_alter
Status: Active » Needs review
StatusFileSize
new4.77 KB

Here's a patch to do the above

  • jonathan1055 committed 46e73ec on 8.x-1.x
    Issue #2861909 by jonathan1055: Exit early to skip unnecessary...
jonathan1055’s picture

Title: Exit early to avoid unnecessary processing in hook_node_form_alter » Exit early to avoid unnecessary processing in hook_form_NODE_FORM_alter
Status: Needs review » Fixed

Fixed.
The change is simpler than the patch look. At the top I added:

// If neither publishing nor unpublishing are enabled for this node type then
// the only thing to do is remove the fields from the form, then exit.
if (!$publishing_enabled && !$unpublishing_enabled) {
  unset($form['publish_on']);
  unset($form['unpublish_on']);
  return;
}

Then two lines near the start are moved closer to where they are needed, and the unrequired conditional is removed.

jonathan1055’s picture

Assigned: jonathan1055 » Unassigned

unassigning

Status: Fixed » Closed (fixed)

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