Version:
Cohesiondx.com

Are you looking for the latest documentation?

Documentation for Acquia Cohesion V6.0 onwards has moved to https://cohesiondocs.acquia.com

    Implementing hooks for custom content entities

    In order to make your custom content entity work with DX8 you will need to alter the suggestions using hook_theme_suggestions_HOOK_alter. DX8 provides a method you can implement inside the hook that will alter the suggestions according to your DX8 setup

    cohesion_templates_suggestions(array &$suggestions, ContentEntityInterface $entity, $view_mode, $hook)

    The first argument is the array of suggestions, the second argument is the entity you are altering the suggestions for, ( usually in $variables['elements'][entity_type] ), the third argument is the view mode used to render the entity, and the last argument the entity type

    For example, if you want to enable paragraphs you need to implement the hook hook_theme_suggestions_HOOK_alter using the cohesion_templates_suggestions method as follows:

    /**
 
     * @inheritdoc
 
     * Implements hook_theme_suggestions_HOOK_alter().
 
     *
 
     */

    function dx8_paragraphs_theme_suggestions_paragraph_alter(array &$suggestions, array &$variables) {
  
      cohesion_templates_suggestions($suggestions, $variables['elements']['#paragraph'], $variables['elements']['#view_mode'], 'paragraph');

    } 
    

    Most of the time the base theme hook is the same as the entity type name, therefore DX8 takes the entity_type to generate its twig file (ex: for a node template the generated twig will have a name of node__template-name). However if the entity_type doesn’t match the base theme hook, you will have to implement a DX8 hook hook_cohesion_templates_ENTITY_TYPE_base_hook_alter in order to provide the right base hook name

    You can find an example of this in the cohesion_template.module 

    /**
 
     * @inheritdoc
 
     * Implements hook_cohesion_templates_ENTITY_TYPE_base_hook_alter().
 
     *
 
     */

    function cohesion_templates_cohesion_templates_block_content_base_hook_alter(&$base_hook) {
  
      $base_hook = 'block';

    }
    

    Without this implementation, twig file names for custom blocks would start with block_content__ where it has to be block__

    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.