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'] ?? [];
Issue fork languages_dropdown-3556639
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
Comment #5
danrodThanks for opening this issue. Would it be possible to fix the PHPCS errors before merging this to the 5.0.x branch? Thanks !
Comment #6
danrodComment #7
danrodComment #8
flyke commentedMR!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.
Comment #9
danrodThanks 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.
Comment #10
danrodComment #11
danrodI 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.
Comment #12
danrodComment #13
danrodI'll merge this to the 5.0.x and 3.0.x branches
Comment #14
danrodComment #15
danrodComment #16
danrod