Problem/Motivation
With markdownify_metadata and schema_metatag both enabled, every request for the Markdown representation of an entity logs two PHP warnings:
Warning: Drupal\schema_metatag\SchemaMetatagManager::parseJsonld():
Argument #1 ($elements) must be passed by reference, value given in
Drupal\markdownify_metadata\MarkdownifyMetadataManager->buildFrontmatter()Warning: Array to string conversion in
Drupal\markdownify_metadata\MarkdownifyMetadataManager->extractMetatags()
Both have the same origin: Schema.org metatags hold their JSON-LD as a nested array, while MarkdownifyMetadataManager treats every metatag value as a scalar.
The frontmatter itself is still produced correctly, so the impact is log noise on every Markdown request, which on a busy site buries genuine errors.
Steps to reproduce
- Install Drupal 11 with
markdownify,markdownify_metadata,metatagandschema_metatag, plus a Schema.org submodule such asschema_article. - Configure Schema.org metatag defaults for a content type.
- Request the Markdown representation of a node of that type, for example
/node/1.md. - Both warnings appear at
/admin/reports/dblogon every request.
Issue fork markdownify-3619685
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 #3
frouco commentedReady to be reviewed
Comment #4
vinodhini.e commentedHi,
Tested this on Drupal 11.4.2 and was able to reproduce the issue following the steps provided in the issue summary.
I applied MR !39 and cleared caches, but the warnings are still being logged when accessing the Markdown representation of a node (/node/{nid}.md).
It appears that MR !39 does not fully resolve the issue on Drupal 11.4.2.
Comment #5
gillesbailleux@vinodhini.e: on a Drupal 11.4.5 instance equipped with PHP 8.4.25, the issue occurs when visiting a node with an .md output which uses the schema_metatag module v.3.0.4
Warning : Drupal\schema_metatag\SchemaMetatagManager::parseJsonld(): Argument #1 ($elements) must be passed by reference, value given dans Drupal\markdownify_metadata\MarkdownifyMetadataManager->buildFrontmatter() (/home/petitefontaine/public_html/web/modules/contrib/markdownify/modules/metadata/src/MarkdownifyMetadataManager.php ligne 433)Comment #6
tbcs commentedTested MR !39 against a clean 1.2.0 on the exact combination reported in #5, and both warnings are gone for me:
- Drupal 11.4.5, PHP 8.4.20, markdownify 1.2.0, schema_metatag 3.0.4, metatag 2.2.0
- Applied the MR diff to a fresh copy of the module,
drush cr- Called
MarkdownifyMetadataManager::buildFrontmatter()for a node with Schema.org WebPage/WebSite tags under an error handler that records every non-deprecation notice: none raised (unpatched: both warnings raised, every request). Theschema:block in the front matter is unchanged.- Confirmed over HTTP too, with
error_level: verbose: a fresh/node/1.mdrequest (cache-busting query string) renders no warning into the body and adds no rows of typephpto watchdog; unpatched, the same request logs both.A small suggestion on the MR itself:
Instead of the string-variable static call, import the class and call it directly:
A
usestatement never triggers autoloading, so the existingclass_exists()guard keeps the dependency optional exactly as before, and it satisfiesDrupal.Classes.FullyQualifiedNamespace(a fully qualified name inline fails phpcs). The variable-class form works, but hides the class from IDEs and static analysis for no gain.