We have the following route defined in module.routing.yml:
module.import.votes:
path: '/node/{node}/votes/import'
defaults:
_title: 'Import Votes'
_form: '\Drupal\aw_import\Form\ImportVotesForm'
allowed_bundles: [poll]
requirements:
_permission: 'import content'
_custom_access: '\Drupal\aw_general\AccessHandler\AccessByNodeTypeHandler::checkAccess'
options:
parameters:
node:
type: 'entity:node'
Background: We use a node type "poll" to show information about polls in parliament and the votes of each deputy is stored in a custom "vote" entity which are imported via a custom form for each poll. The route defines the path to this import form.
Until one of the last Drupal updates this worked just fine. What now leads to trouble is the "allowed_bundles" default parameter in this route definition. When you access the path '/node/{node}/votes/import' now the following error message appears:
TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, array given in htmlspecialchars() (line 432 of core\lib\Drupal\Component\Utility\Html.php).
As I found out the following code leads to this errors. template_preprocess_html() in core/includes/theme.inc, line 1370:
$head_title = [
// Marking the title as safe since it has had the tags stripped.
'title' => Markup::create(trim(strip_tags($variables['page']['#title']))),
'name' => $site_config->get('name'),
];
And here it is $variables['page']['#title']
- it is a TranslateableMarkup class with the above allowed_bundles
added as arguments @allowed_bundles
and %allowed_bundles
. These arguments are arrays but they are sent to a method FormattableMarkup::placeholderFormat() which seems to expect them to be strings.
I do not know which changes in Drupal core caused this issue - as I said it worked in this way now for years but not anymore.