Skip to content

Allows any entity to be embedded using a WYSIWYG and text format.

Notifications You must be signed in to change notification settings

DevinCarlson/entity_embed

 
 

Repository files navigation

Entity Embed Module

Travis build status Scrutinizer code quality

Entity Embed module allows any entity to be embedded using a text editor.

Requirements

Installation

Entity Embed can be installed via the standard Drupal installation process.

Configuration

  • Install and enable Embed module.
  • Install and enable Entity Embed module.
  • Go to the 'Text formats and editors' configuration page: /admin/config/content/formats, and for each text format/editor combo where you want to embed entities, do the following:
    • Enable the 'Display embedded entities' filter.
    • Drag and drop the 'E' button into the Active toolbar.
    • If the text format uses the 'Limit allowed HTML tags and correct faulty HTML' filter, ensure the necessary tags and attributes are whitelisted: add <drupal-entity data-entity-type data-entity-uuid data-entity-id data-view-mode data-entity-embed-display data-entity-embed-settings data-align data-caption> to the 'Allowed HTML tags' setting. (Will happen automatically after https://www.drupal.org/node/2554687.)

Usage

  • For example, create a new Article content.
  • Click on the 'E' button in the text editor.
  • Enter part of the title of the entity you're looking for and select one of the search results.
  • For Display as, choose one of the following options:
    • Rendered Entity
    • Entity ID
    • Label
  • If chosen Rendered Entity, choose one of the following options for View mode:
    • Default
    • Full content
    • RSS
    • Search index
    • Search result highlighting input
  • Optionally, choose to align left, center or right.

Embedding entities without WYSIWYG

Users should be embedding entities using the CKEditor WYSIWYG button as described above. This section is more technical about the HTML markup that is used to embed the actual entity.

Embed by UUID (recommended):

<drupal-entity data-entity-type="node" data-entity-uuid="07bf3a2e-1941-4a44-9b02-2d1d7a41ec0e" data-entity-embed-display="entity_reference:entity_reference_entity_view" data-entity-embed-settings='{"view_mode":"teaser"}' />

Embed by ID (not recommended):

<drupal-entity data-entity-type="node" data-entity-id="1" data-entity-embed-display="entity_reference:entity_reference_entity_view" data-entity-embed-settings='{"view_mode":"teaser"}' />

Entity Embed Display Plugins

Embedding entities uses an Entity Embed Display plugin, provided in the data-entity-embed-display attribute. By default we provide four different Entity Embed Display plugins out of the box:

  • entity_reference:formatter_id: Renders the entity using a specific Entity Reference field formatter.
  • entity_reference:entity_reference_label: Renders the entity using the "Label" formatter.
  • file:formatter_id: Renders the entity using a specific File field formatter. This will only work if the entity is a file entity type.
  • image:formatter_id: Renders the entity using a specific Image field formatter. This will only work if the entity is a file entity type, and the file is an image.

Configuration for the Entity Embed Display plugin can be provided by using a data-entity-embed-settings attribute, which contains a JSON-encoded array value. Note that care must be used to use single quotes around the attribute value since JSON-encoded arrays typically contain double quotes.

The above examples render the entity using the entity_reference_entity_view formatter from the Entity Reference module, using the teaser view mode.

About

Allows any entity to be embedded using a WYSIWYG and text format.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 92.5%
  • JavaScript 6.6%
  • Other 0.9%