Some PHP 8.1 compatibility problems were identified while working on #3261505: In php 8.1 the explode function throws a notice when default value is null.

Exception: Deprecated function: Automatic conversion of false to array is deprecated
template_preprocess_page_manager_wizard_tree()() (Line: 114)

Comments

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new1.21 KB

Will this work? I don't know.

anybody’s picture

PUSH as PHP 8.1 is becoming more important.

This is the affected line:

$parent[$step] = ...

and this is the whole function:

/**
 * Preprocess function for page-manager-wizard-tree.html.twig.
 */
function template_preprocess_page_manager_wizard_tree(&$variables) {
  /** @var $wizard \Drupal\ctools\Wizard\FormWizardInterface|\Drupal\ctools\Wizard\EntityFormWizardInterface */
  $wizard = $variables['wizard'];
  $cached_values = $variables['cached_values'];
  $tree = $variables['tree'];
  $variables['step'] = $wizard->getStep($cached_values);

  foreach ($wizard->getOperations($cached_values) as $step => $operation) {
    $parameters = $wizard->getNextParameters($cached_values);
    // Override step to be the step we want.
    $parameters['step'] = $step;

    // Fill in parents if there are breadcrumbs.
    $parent =& $tree;
    if (isset($operation['breadcrumbs'])) {
      foreach ($operation['breadcrumbs'] as $breadcrumb) {
        $breadcrumb_string = (string) $breadcrumb;
        if (!isset($parent[$breadcrumb_string])) {
          $parent[$breadcrumb_string] = [
            'title' => $breadcrumb,
            'children' => [],
          ];
        }
        $parent =& $parent[$breadcrumb_string]['children'];
      }
    }

    $parent[$step] = [
      'title' => !empty($operation['title']) ? $operation['title'] : '',
      'url' => new Url($wizard->getRouteName(), $parameters),
      'step' => $step,
    ];
  }

  $variables['tree'] = $tree;
}

So indeed I guess $tree is FALSE somewhere and should be better checked?

fskreuz’s picture

It's a bit complicated because #tree is declared as a variable of the page_manager_wizard_tree theme and has a default value of [], which becomes the tree property in the variables array (See page_manager_ui_theme()).

But then we're dealing with a form here, and #tree is also the #tree form render element property for form element tree-ness. The FALSE is coming from Drupal\Core\Form\FormBuilder::doBuildForm()'s logic of building the tree-ness of a form element.

The patch works around this issue by treating tree as what page manager wants it to be, an array "tree" of things. But I think the more proper fix is to rename #tree to something else to avoid the collision. However, I don't know the implications of this change.

fskreuz’s picture

Here's a different patch that renames #tree to something else to avoid the collision.

fskreuz’s picture

StatusFileSize
new2.47 KB

Found a few more while working with Page Manager today. The additions avoid passing $page->getPath(), which is NULL during page creation, to strpos() and preg_match_all().

anybody’s picture

Thanks @fskreuz! Also for your explanations in #4. I guess it would now make sense if a maintainer would have a look?

anybody’s picture

fskreuz’s picture

@anybody re: #7, makes sense to loop in a maintainer to go over that one.

  • japerry committed 5d068bd on 8.x-4.x
    Issue #3263077 by fskreuz, DamienMcKenna, japerry: PHP 8.1 compatibility...

japerry credited undefined.

japerry’s picture

Status: Needs review » Fixed

Lets bump the tree conversation to another issue. #tree != tree. And we see $variable['tree'] is being set at the end, even with the tree_structure change... so I don't want to mess with that here.

The other PHP 8.1 issues have been fixed. Sorry I didn't get around to getting my patch in here, but it roughly does the same as the patches above.

Status: Fixed » Closed (fixed)

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