diff --git a/entity_embed.module b/entity_embed.module index abba0ab..c41c2d5 100644 --- a/entity_embed.module +++ b/entity_embed.module @@ -7,6 +7,33 @@ */ /** + * Implements hook_theme(). + */ +function entity_embed_theme() { + return [ + 'entity_embed_container' => [ + 'render element' => 'element', + ], + ]; +} + +/** + * Prepares variables for entity embed container templates. + * + * Default template: entity-embed-container.html.twig. + * + * @param array $variables + * An associative array containing: + * - element: An associative array containing the properties of the element. + * Properties used: #attributes, #children. + */ +function template_preprocess_entity_embed_container(&$variables) { + $variables['element'] += ['#attributes' => []]; + $variables['attributes'] = $variables['element']['#attributes']; + $variables['children'] = $variables['element']['#children']; +} + +/** * Implements hook_entity_embed_display_plugins_alter() on behalf of file.module. */ function file_entity_embed_display_plugins_alter(array &$plugins) { diff --git a/src/EntityHelperTrait.php b/src/EntityHelperTrait.php index 8303637..5692689 100644 --- a/src/EntityHelperTrait.php +++ b/src/EntityHelperTrait.php @@ -194,8 +194,10 @@ trait EntityHelperTrait { // Build and render the Entity Embed Display plugin, allowing modules to // alter the result before rendering. $build = array( - '#theme_wrappers' => ['container'], - '#attributes' => [], + '#theme_wrappers' => ['entity_embed_container'], + '#attributes' => ['class' => ['embedded-entity']], + '#entity' => $entity, + '#context' => $context, ); $build['entity'] = $this->renderEntityEmbedDisplayPlugin( $entity, diff --git a/src/Tests/EntityEmbedFilterTest.php b/src/Tests/EntityEmbedFilterTest.php index b18c3d3..95bfa38 100644 --- a/src/Tests/EntityEmbedFilterTest.php +++ b/src/Tests/EntityEmbedFilterTest.php @@ -19,7 +19,14 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase { * * @var array */ - public static $modules = ['file', 'image', 'entity_embed', 'entity_embed_test', 'node', 'ckeditor']; + public static $modules = [ + 'file', + 'image', + 'entity_embed', + 'entity_embed_test', + 'node', + 'ckeditor', + ]; /** * Tests the entity_embed filter. diff --git a/templates/entity-embed-container.html.twig b/templates/entity-embed-container.html.twig new file mode 100644 index 0000000..43fedc7 --- /dev/null +++ b/templates/entity-embed-container.html.twig @@ -0,0 +1,15 @@ +{# +/** + * @file + * Default theme implementation of a container used to wrap embedded entities. + * + * Available variables: + * - attributes: HTML attributes for the containing element. + * - children: The rendered child elements of the container. + * + * @see template_preprocess_entity_embed_container() + * + * @ingroup themeable + */ +#} +{{ children }}