Problem/Motivation
Metatags that contain tokens referencing unavailable field data (e.g., [node:summary]when the body field is empty) were being included in the markdown attributes as raw token strings instead of being skipped.
Example:
meta-description: "[node:summary]"
This occurs because:
- Some tokens depend on specific field data that may not be available or loaded
- Tokens like
[node:title]and[site:name]work because they're always available - Tokens like
[node:summary]fail when the referenced field is empty or unprocessed - The previous implementation would include the unconverted token value regardless
This results in broken/incomplete metatag values being exposed to the frontend.
Steps to reproduce
- Create a node with an empty body field
- Configure metatags to include tokens that depend on field data (e.g.,
[node:summary]) - Enable markdown attributes in Content First settings
- View the generated content attributes
- Observe: Unconverted tokens appear as raw strings in metatag attributes
Proposed resolution
Simplify the token replacement logic in ContentFirstBuilder::extractAttributes()to:
- Attempt to replace all tokens in metatag values using the token service
- Only add the metatag to attributes if:
- The token replacement was successful (no remaining brackets
[in the value) - The resulting value is not empty
- The token replacement was successful (no remaining brackets
- Skip any metatags that contain unreplaced tokens (indicating unavailable field data)
This prevents incomplete/broken token values from being included in the output while preserving tokens that successfully resolve.
Code change:
$replaced_value = $token_service->replace($value, [$entity->getEntityTypeId() => $entity]);
// Only add if no remaining brackets (token was replaced successfully).
if (strpos($replaced_value, '[') === FALSE && !empty($replaced_value)) {
$clean_value = trim(strip_tags(html_entity_decode($replaced_value)));
if (!empty($clean_value)) {
$attributes['meta-' . $key] = $clean_value;
}
}
User interface changes
None. This is an internal logic fix that improves data quality without changing the UI.
API changes
None. The extractAttributes()method signature remains unchanged. The behavior change is internal (skipping unconverted tokens instead of including them).
Data model changes
None. No database schema or data model changes required.
Summary of Changes
The fix ensures that:
-
[node:title]
✓ Still works (always available) -
[site:name]
✓ Still works (config value) -
[node:summary]
✗ Skipped (not available) instead of showing as[node:summary]
Only properly resolved tokens appear in the markdown attributes output.
Issue fork content_first-3571700
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
eduardo morales albertiReady to review
Comment #5
eduardo morales albertiFixed!