Problem/Motivation

This module generates multiple php errors when editing a canvas page

Steps to reproduce

- Add and enable this module, make sure you have a languages dropdown block, for example on your page heading navigation
- Use Drupal Canvas, create or edit a canvas page
- Visit /admin/reports/dblog en notice multiple php errors from this module

Proposed resolution

It all comes from missing or empty array values in languages_dropdown/src/Plugin/Block/LangDropBootstrapBlock.php. In the blockForm function, fallbacks are always provided in case the array keys do not exist, like:

    if (isset($config['languages_dropdown_bootstrap']) && !empty($config['languages_dropdown_bootstrap'])) {
      $settings = $config['languages_dropdown_bootstrap'];
    }
    else {
      $settings = [];
    }

However, in other functions, there are no checks so these result in php errors. For example in the function build() :
$settings = $this->configuration['languages_dropdown_bootstrap'];
This throws an error when editing a canvas page, but could be fixed like:
$settings = $this->configuration['languages_dropdown_bootstrap'] ?? [];

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

flyke created an issue. See original summary.

flyke changed the visibility of the branch 3556639-multiple-warning-undefined to hidden.

danrod’s picture

Thanks for opening this issue. Would it be possible to fix the PHPCS errors before merging this to the 5.0.x branch? Thanks !

danrod’s picture

Status: Active » Needs work
danrod’s picture

Assigned: Unassigned » danrod
flyke’s picture

Status: Needs work » Reviewed & tested by the community

MR!18 applies to latest languages_dropdown 5.0.x-dev. It also applies to 5.0.2.
It does conflict with MR from #3556639 btw, just noting that. You cant apply the MR of both issues together.

After installing languages_dropdown with MR!22 in a project using latest canvas dev, I was able to place the 'Language switcher (Bootstrap)' component and everything works.

danrod’s picture

Thanks for confirming that it works, could you look into the PHPCS errors, please? I want to merge this to the 5.0.x branch, I'll take care of backporting the changes to the other branches.

danrod’s picture

Status: Reviewed & tested by the community » Needs work
danrod’s picture

I fixed the PHPCS errors and this is ready for review, just in case anyone wants to take an extra look, otherwise I will merge this to the 5.0.x and 3.0.x branches.

danrod’s picture

Status: Needs work » Needs review
danrod’s picture

I'll merge this to the 5.0.x and 3.0.x branches

danrod’s picture

Status: Needs review » Reviewed & tested by the community
danrod’s picture

Assigned: danrod » Unassigned
danrod’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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