Acquia Cohesion renames to Site Studio from version 6.2. Tell me more.

Can I template custom entity types?

Yes, you can template custom entity types. There are some hooks that need to be implemented.

You can template custom entity types using Acquia Cohesion, there are some hooks which need to be implemented within your custom code. 
Below are some example hooks, to show how to implement, in this example we're enabling templating of the product type that comes with Drupal commerce.

The below hook alters the content variable used for the entity type. For nodes the main content (fields) is stored in the 'content' variable, but it can be different for other entity types. In this example the product entity type returns its content in 'product'.

/**
 * Alter the variable name where the main content is stored for a particular entity type
 *
 *
 * @param  $variable
 *   The variable used for the entity type
 * 
 * Implements hook_dx8_ENTITY_TYPE_drupal_field_prefix_alter().
 */
function hook_dx8_commerce_product_drupal_field_prefix_alter(&$variable) {
      $variable = 'product';
}

This next hook alters the theme template suggestions and runs it through the cohesion template suggestions.

/**
 * @param array $suggestions
 * @param array $variables
 * 
 * Implements hook_theme_suggestions_HOOK_alter().

 */
function hook_theme_suggestions_commerce_product_alter(array &$suggestions, array &$variables) {
  cohesion_templates_suggestions($suggestions, $variables['elements']['#commerce_product'], $variables['elements']['#view_mode'], 'commerce_product');
}

 

DX8 knowledge base icon

Frequently asked questions

Get instant answers to common questions. Available online 24/7.

Find answers

Raise a ticket icon

Raise a support ticket

To raise a ticket, sign into Acquia Cloud and select Help in the top menu.

Raise support ticket

Acquia

Copyright © 2020 Acquia, Inc. All Rights Reserved. Drupal is a registered trademark of Dries Buytaert.