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

  1. Create a node with an empty body field
  2. Configure metatags to include tokens that depend on field data (e.g., [node:summary])
  3. Enable markdown attributes in Content First settings
  4. View the generated content attributes
  5. Observe: Unconverted tokens appear as raw strings in metatag attributes

Proposed resolution

Simplify the token replacement logic in ContentFirstBuilder::extractAttributes()to:

  1. Attempt to replace all tokens in metatag values using the token service
  2. Only add the metatag to attributes if:
    • The token replacement was successful (no remaining brackets [in the value)
    • The resulting value is not empty
  3. 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.

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

eduardo morales alberti’s picture

Status: Active » Needs review

Ready to review

eduardo morales alberti’s picture

Status: Needs review » Fixed

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.