A Drupal module that adds granular control over view modes for entity rendering through the Markdownify converter.
This module extends the Markdownify contrib module to allow configuration of which view mode is used when rendering entities (nodes, taxonomy terms, etc.) in Markdown format.
- Global entity-type defaults: Set a default view mode for each entity type (e.g., 'teaser' for all nodes)
- Per-bundle overrides: Override the global default for specific content types or vocabularies
- Hierarchical fallback: Intelligent system to determine the correct view mode to use
- View mode validation: Ensures only valid, configured view modes are applied
- Drupal 10+ or 11+
- Markdownify contrib module
-
Install the module:
drush en markdownify_viewmodes
-
Clear cache:
drush cr
- Navigate to Administration > Configuration > Content > Markdownify
- Expand each entity type section
- Select a "Default view mode" for that entity type
- Save
- Go to the bundle edit form (e.g., Structure > Content Types > Manage > Article)
- Open the Markdownify tab
- Check "Override global view mode for Markdownify"
- Select a view mode
- Save
When rendering an entity through Markdownify, the module checks for the view mode in this order:
- Bundle override (if enabled)
- Entity-type default (from markdownify settings)
- 'full' (Drupal's default fallback)
Example: For an article node
- First checks if there's a bundle override for article nodes
- If not, checks if there's an entity-type default for all nodes
- If not, uses 'full' view mode
Get the resolved view mode for an entity:
$resolver = \Drupal::service('markdownify_viewmodes.view_mode_resolver');
$view_mode = $resolver->getViewMode($entity);Internal methods (less commonly needed):
$resolver->getBundleViewMode($entity_type_id, $bundle);
$resolver->getEntityTypeDefaultViewMode($entity_type_id);
$resolver->validateViewMode($entity_type_id, $bundle, $view_mode);This module implements this hook to rebuild entities with the configured view mode during Markdownify rendering. Cache dependencies are properly managed for invalidation on config changes.
Stored in markdownify.settings as third-party settings:
third_party_settings:
markdownify_viewmodes:
entity_types:
node: teaser
taxonomy_term: fullStored on bundle entities (node types, vocabularies, etc.) as third-party settings:
third_party_settings:
markdownify_viewmodes:
enable_override: true
view_mode: default- View mode resolution is cached through entity view builder caching
- Config changes properly invalidate render cache via cache dependencies
- No database queries are added by this module
- Service instantiation is lazy (created only when accessed)
Follows Drupal's default licensing.