Loading README.md +3 −3 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ Entity Embed can be installed via the * If the text format uses the 'Limit allowed HTML tags and correct faulty HTML' filter, ensure the necessary tags and attributes were automatically whitelisted: ```<drupal-entity data-entity-type data-entity-uuid data-view-mode data-entity-embed-display data-entity-embed-settings data-align data-caption data-embed-button>``` ```<drupal-entity data-entity-type data-entity-uuid data-view-mode data-entity-embed-display data-entity-embed-display-settings data-align data-caption data-embed-button>``` appears in the 'Allowed HTML tags' setting. *Warning: If you were using the module in very early pre-alpha stages you might need to add `data-entity-id` to the list of allowed Loading Loading @@ -71,7 +71,7 @@ that is used to embed the actual entity. ### Example: ```html <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"}' /> <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-display-settings='{"view_mode":"teaser"}' /> ``` ## Entity Embed Display Plugins Loading @@ -91,7 +91,7 @@ different Entity Embed Display plugins out of the box: 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 using a `data-entity-embed-display-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. Loading entity_embed.install +32 −0 Original line number Diff line number Diff line Loading @@ -53,3 +53,35 @@ function entity_embed_update_8002() { ->set('rendered_entity_mode', TRUE) ->save(); } /** * Updates allowed HTML for all filter format config entities that have an * Entity Embed button. */ function entity_embed_update_8003() { $buttons = \Drupal::entityTypeManager()->getStorage('embed_button')->loadMultiple(); $filter_formats_with_embed_button = []; // Get filter formats from editors with entity embed button. foreach (\Drupal::entityTypeManager()->getStorage('editor')->loadMultiple() as $editor) { foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($editor->getSettings())) as $settings_value) { foreach ($buttons as $button) { if ($settings_value == $button->id()) { $filter_formats_with_embed_button[] = $editor->getFilterFormat(); } } } } foreach ($filter_formats_with_embed_button as $filter_format) { foreach ($filter_format->filters()->getAll() as $filter) { if (isset($filter->getConfiguration()['settings']['allowed_html'])) { $allowed_html = $filter->getConfiguration()['settings']['allowed_html']; if (strpos($allowed_html, 'data-entity-embed-settings')) { $allowed_html = str_replace('data-entity-embed-settings', 'data-entity-embed-settings data-entity-embed-display-settings', $allowed_html); $filter_format->setFilterConfig($filter->getPluginId(), ['settings' => ['allowed_html' => $allowed_html]]); $filter_format->save(); } } } } } js/plugins/drupalentity/plugin.js +5 −5 Original line number Diff line number Diff line Loading @@ -27,8 +27,8 @@ // Generic command for adding/editing entities of all types. editor.addCommand('editdrupalentity', { allowedContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', allowedContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', modes: { wysiwyg : 1 }, canUndo: true, exec: function (editor, data) { Loading Loading @@ -82,8 +82,8 @@ // Register the entity embed widget. editor.widgets.add('drupalentity', { // Minimum HTML which is required by this widget to work. allowedContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', allowedContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', // Simply recognize the element as our own. The inner markup if fetched // and inserted the init() callback, since it requires the actual DOM Loading Loading @@ -135,7 +135,7 @@ editor.ui.addButton(button.id, { label: button.label, data: button, allowedContent: 'drupal-entity[!data-entity-type,!data-entity-uuid,!data-entity-embed-display,!data-entity-embed-settings,!data-align,!data-caption,!data-embed-button]', allowedContent: 'drupal-entity[!data-entity-type,!data-entity-uuid,!data-entity-embed-display,!data-entity-embed-display-settings,!data-align,!data-caption,!data-embed-button]', click: function(editor) { editor.execCommand('editdrupalentity', this.data); }, Loading src/EntityEmbedBuilder.php +4 −4 Original line number Diff line number Diff line Loading @@ -45,9 +45,9 @@ class EntityEmbedBuilder implements EntityEmbedBuilderInterface { */ public function buildEntityEmbed(EntityInterface $entity, array $context = []) { // Support the deprecated view-mode data attribute. if (isset($context['data-view-mode']) && !isset($context['data-entity-embed-display']) && !isset($context['data-entity-embed-settings'])) { if (isset($context['data-view-mode']) && !isset($context['data-entity-embed-display']) && !isset($context['data-entity-embed-display-settings'])) { $context['data-entity-embed-display'] = 'entity_reference:entity_reference_entity_view'; $context['data-entity-embed-settings'] = ['view_mode' => &$context['data-view-mode']]; $context['data-entity-embed-display-settings'] = ['view_mode' => &$context['data-view-mode']]; } // Merge in default attributes. Loading @@ -55,7 +55,7 @@ class EntityEmbedBuilder implements EntityEmbedBuilderInterface { 'data-entity-type' => $entity->getEntityTypeId(), 'data-entity-uuid' => $entity->uuid(), 'data-entity-embed-display' => 'entity_reference:entity_reference_entity_view', 'data-entity-embed-settings' => [], 'data-entity-embed-display-settings' => [], ]; // The default Entity Embed Display plugin has been deprecated by the Loading Loading @@ -83,7 +83,7 @@ class EntityEmbedBuilder implements EntityEmbedBuilderInterface { $build['entity'] = $this->buildEntityEmbedDisplayPlugin( $entity, $context['data-entity-embed-display'], $context['data-entity-embed-settings'], $context['data-entity-embed-display-settings'], $context ); Loading src/Form/EntityEmbedDialog.php +15 −15 Original line number Diff line number Diff line Loading @@ -154,12 +154,12 @@ class EntityEmbedDialog extends FormBase { $form_state->set('entity_element', isset($input['editor_object']) ? $input['editor_object'] : array()); } $entity_element += $form_state->get('entity_element'); $entity_element += array( $entity_element += [ 'data-entity-type' => $embed_button->getTypeSetting('entity_type'), 'data-entity-uuid' => '', 'data-entity-embed-display' => 'entity_reference:entity_reference_entity_view', 'data-entity-embed-settings' => array(), ); 'data-entity-embed-display-settings' => isset($form_state->get('entity_element')['data-entity-embed-settings']) ? $form_state->get('entity_element')['data-entity-embed-settings'] : [], ]; $form_state->set('entity_element', $entity_element); $entity = $this->entityTypeManager->getStorage($entity_element['data-entity-type']) ->loadByProperties(['uuid' => $entity_element['data-entity-uuid']]); Loading Loading @@ -414,15 +414,15 @@ class EntityEmbedDialog extends FormBase { '#required' => TRUE, '#ajax' => array( 'callback' => '::updatePluginConfigurationForm', 'wrapper' => 'data-entity-embed-settings-wrapper', 'wrapper' => 'data-entity-embed-display-settings-wrapper', 'effect' => 'fade', ), // Hide the selection if only one option is available. '#access' => count($display_plugin_options) > 1, ); $form['attributes']['data-entity-embed-settings'] = array( $form['attributes']['data-entity-embed-display-settings'] = array( '#type' => 'container', '#prefix' => '<div id="data-entity-embed-settings-wrapper">', '#prefix' => '<div id="data-entity-embed-display-settings-wrapper">', '#suffix' => '</div>', ); $form['attributes']['data-embed-button'] = array( Loading @@ -431,13 +431,13 @@ class EntityEmbedDialog extends FormBase { ); $plugin_id = !empty($values['attributes']['data-entity-embed-display']) ? $values['attributes']['data-entity-embed-display'] : $entity_element['data-entity-embed-display']; if (!empty($plugin_id)) { if (is_string($entity_element['data-entity-embed-settings'])) { $entity_element['data-entity-embed-settings'] = Json::decode($entity_element['data-entity-embed-settings']); if (is_string($entity_element['data-entity-embed-display-settings'])) { $entity_element['data-entity-embed-display-settings'] = Json::decode($entity_element['data-entity-embed-display-settings']); } $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $entity_element['data-entity-embed-settings']); $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $entity_element['data-entity-embed-display-settings']); $display->setContextValue('entity', $entity); $display->setAttributes($entity_element); $form['attributes']['data-entity-embed-settings'] += $display->buildConfigurationForm($form, $form_state); $form['attributes']['data-entity-embed-display-settings'] += $display->buildConfigurationForm($form, $form_state); } // When Drupal core's filter_align is being used, the text editor may Loading Loading @@ -575,7 +575,7 @@ class EntityEmbedDialog extends FormBase { ->loadByProperties(['uuid' => $entity_element['data-entity-uuid']]); $entity = current($entity) ?: NULL; $plugin_id = $entity_element['data-entity-embed-display']; $plugin_settings = $entity_element['data-entity-embed-settings'] ?: array(); $plugin_settings = $entity_element['data-entity-embed-display-settings'] ?: array(); $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $plugin_settings); $display->setContextValue('entity', $entity); $display->setAttributes($entity_element); Loading @@ -596,7 +596,7 @@ class EntityEmbedDialog extends FormBase { * The form state. */ public function updatePluginConfigurationForm(array &$form, FormStateInterface $form_state) { return $form['attributes']['data-entity-embed-settings']; return $form['attributes']['data-entity-embed-display-settings']; } /** Loading Loading @@ -732,7 +732,7 @@ class EntityEmbedDialog extends FormBase { ->loadByProperties(['uuid' => $entity_element['data-entity-uuid']]); $entity = current($entity); $plugin_id = $entity_element['data-entity-embed-display']; $plugin_settings = $entity_element['data-entity-embed-settings'] ?: array(); $plugin_settings = $entity_element['data-entity-embed-display-settings'] ?: array(); $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $plugin_settings); $display->setContextValue('entity', $entity); $display->setAttributes($entity_element); Loading @@ -750,8 +750,8 @@ class EntityEmbedDialog extends FormBase { } else { // Serialize entity embed settings to JSON string. if (!empty($values['attributes']['data-entity-embed-settings'])) { $values['attributes']['data-entity-embed-settings'] = Json::encode($values['attributes']['data-entity-embed-settings']); if (!empty($values['attributes']['data-entity-embed-display-settings'])) { $values['attributes']['data-entity-embed-display-settings'] = Json::encode($values['attributes']['data-entity-embed-display-settings']); } // Filter out empty attributes. Loading Loading
README.md +3 −3 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ Entity Embed can be installed via the * If the text format uses the 'Limit allowed HTML tags and correct faulty HTML' filter, ensure the necessary tags and attributes were automatically whitelisted: ```<drupal-entity data-entity-type data-entity-uuid data-view-mode data-entity-embed-display data-entity-embed-settings data-align data-caption data-embed-button>``` ```<drupal-entity data-entity-type data-entity-uuid data-view-mode data-entity-embed-display data-entity-embed-display-settings data-align data-caption data-embed-button>``` appears in the 'Allowed HTML tags' setting. *Warning: If you were using the module in very early pre-alpha stages you might need to add `data-entity-id` to the list of allowed Loading Loading @@ -71,7 +71,7 @@ that is used to embed the actual entity. ### Example: ```html <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"}' /> <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-display-settings='{"view_mode":"teaser"}' /> ``` ## Entity Embed Display Plugins Loading @@ -91,7 +91,7 @@ different Entity Embed Display plugins out of the box: 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 using a `data-entity-embed-display-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. Loading
entity_embed.install +32 −0 Original line number Diff line number Diff line Loading @@ -53,3 +53,35 @@ function entity_embed_update_8002() { ->set('rendered_entity_mode', TRUE) ->save(); } /** * Updates allowed HTML for all filter format config entities that have an * Entity Embed button. */ function entity_embed_update_8003() { $buttons = \Drupal::entityTypeManager()->getStorage('embed_button')->loadMultiple(); $filter_formats_with_embed_button = []; // Get filter formats from editors with entity embed button. foreach (\Drupal::entityTypeManager()->getStorage('editor')->loadMultiple() as $editor) { foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($editor->getSettings())) as $settings_value) { foreach ($buttons as $button) { if ($settings_value == $button->id()) { $filter_formats_with_embed_button[] = $editor->getFilterFormat(); } } } } foreach ($filter_formats_with_embed_button as $filter_format) { foreach ($filter_format->filters()->getAll() as $filter) { if (isset($filter->getConfiguration()['settings']['allowed_html'])) { $allowed_html = $filter->getConfiguration()['settings']['allowed_html']; if (strpos($allowed_html, 'data-entity-embed-settings')) { $allowed_html = str_replace('data-entity-embed-settings', 'data-entity-embed-settings data-entity-embed-display-settings', $allowed_html); $filter_format->setFilterConfig($filter->getPluginId(), ['settings' => ['allowed_html' => $allowed_html]]); $filter_format->save(); } } } } }
js/plugins/drupalentity/plugin.js +5 −5 Original line number Diff line number Diff line Loading @@ -27,8 +27,8 @@ // Generic command for adding/editing entities of all types. editor.addCommand('editdrupalentity', { allowedContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', allowedContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', modes: { wysiwyg : 1 }, canUndo: true, exec: function (editor, data) { Loading Loading @@ -82,8 +82,8 @@ // Register the entity embed widget. editor.widgets.add('drupalentity', { // Minimum HTML which is required by this widget to work. allowedContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]', allowedContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', requiredContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-display-settings,data-align,data-caption]', // Simply recognize the element as our own. The inner markup if fetched // and inserted the init() callback, since it requires the actual DOM Loading Loading @@ -135,7 +135,7 @@ editor.ui.addButton(button.id, { label: button.label, data: button, allowedContent: 'drupal-entity[!data-entity-type,!data-entity-uuid,!data-entity-embed-display,!data-entity-embed-settings,!data-align,!data-caption,!data-embed-button]', allowedContent: 'drupal-entity[!data-entity-type,!data-entity-uuid,!data-entity-embed-display,!data-entity-embed-display-settings,!data-align,!data-caption,!data-embed-button]', click: function(editor) { editor.execCommand('editdrupalentity', this.data); }, Loading
src/EntityEmbedBuilder.php +4 −4 Original line number Diff line number Diff line Loading @@ -45,9 +45,9 @@ class EntityEmbedBuilder implements EntityEmbedBuilderInterface { */ public function buildEntityEmbed(EntityInterface $entity, array $context = []) { // Support the deprecated view-mode data attribute. if (isset($context['data-view-mode']) && !isset($context['data-entity-embed-display']) && !isset($context['data-entity-embed-settings'])) { if (isset($context['data-view-mode']) && !isset($context['data-entity-embed-display']) && !isset($context['data-entity-embed-display-settings'])) { $context['data-entity-embed-display'] = 'entity_reference:entity_reference_entity_view'; $context['data-entity-embed-settings'] = ['view_mode' => &$context['data-view-mode']]; $context['data-entity-embed-display-settings'] = ['view_mode' => &$context['data-view-mode']]; } // Merge in default attributes. Loading @@ -55,7 +55,7 @@ class EntityEmbedBuilder implements EntityEmbedBuilderInterface { 'data-entity-type' => $entity->getEntityTypeId(), 'data-entity-uuid' => $entity->uuid(), 'data-entity-embed-display' => 'entity_reference:entity_reference_entity_view', 'data-entity-embed-settings' => [], 'data-entity-embed-display-settings' => [], ]; // The default Entity Embed Display plugin has been deprecated by the Loading Loading @@ -83,7 +83,7 @@ class EntityEmbedBuilder implements EntityEmbedBuilderInterface { $build['entity'] = $this->buildEntityEmbedDisplayPlugin( $entity, $context['data-entity-embed-display'], $context['data-entity-embed-settings'], $context['data-entity-embed-display-settings'], $context ); Loading
src/Form/EntityEmbedDialog.php +15 −15 Original line number Diff line number Diff line Loading @@ -154,12 +154,12 @@ class EntityEmbedDialog extends FormBase { $form_state->set('entity_element', isset($input['editor_object']) ? $input['editor_object'] : array()); } $entity_element += $form_state->get('entity_element'); $entity_element += array( $entity_element += [ 'data-entity-type' => $embed_button->getTypeSetting('entity_type'), 'data-entity-uuid' => '', 'data-entity-embed-display' => 'entity_reference:entity_reference_entity_view', 'data-entity-embed-settings' => array(), ); 'data-entity-embed-display-settings' => isset($form_state->get('entity_element')['data-entity-embed-settings']) ? $form_state->get('entity_element')['data-entity-embed-settings'] : [], ]; $form_state->set('entity_element', $entity_element); $entity = $this->entityTypeManager->getStorage($entity_element['data-entity-type']) ->loadByProperties(['uuid' => $entity_element['data-entity-uuid']]); Loading Loading @@ -414,15 +414,15 @@ class EntityEmbedDialog extends FormBase { '#required' => TRUE, '#ajax' => array( 'callback' => '::updatePluginConfigurationForm', 'wrapper' => 'data-entity-embed-settings-wrapper', 'wrapper' => 'data-entity-embed-display-settings-wrapper', 'effect' => 'fade', ), // Hide the selection if only one option is available. '#access' => count($display_plugin_options) > 1, ); $form['attributes']['data-entity-embed-settings'] = array( $form['attributes']['data-entity-embed-display-settings'] = array( '#type' => 'container', '#prefix' => '<div id="data-entity-embed-settings-wrapper">', '#prefix' => '<div id="data-entity-embed-display-settings-wrapper">', '#suffix' => '</div>', ); $form['attributes']['data-embed-button'] = array( Loading @@ -431,13 +431,13 @@ class EntityEmbedDialog extends FormBase { ); $plugin_id = !empty($values['attributes']['data-entity-embed-display']) ? $values['attributes']['data-entity-embed-display'] : $entity_element['data-entity-embed-display']; if (!empty($plugin_id)) { if (is_string($entity_element['data-entity-embed-settings'])) { $entity_element['data-entity-embed-settings'] = Json::decode($entity_element['data-entity-embed-settings']); if (is_string($entity_element['data-entity-embed-display-settings'])) { $entity_element['data-entity-embed-display-settings'] = Json::decode($entity_element['data-entity-embed-display-settings']); } $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $entity_element['data-entity-embed-settings']); $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $entity_element['data-entity-embed-display-settings']); $display->setContextValue('entity', $entity); $display->setAttributes($entity_element); $form['attributes']['data-entity-embed-settings'] += $display->buildConfigurationForm($form, $form_state); $form['attributes']['data-entity-embed-display-settings'] += $display->buildConfigurationForm($form, $form_state); } // When Drupal core's filter_align is being used, the text editor may Loading Loading @@ -575,7 +575,7 @@ class EntityEmbedDialog extends FormBase { ->loadByProperties(['uuid' => $entity_element['data-entity-uuid']]); $entity = current($entity) ?: NULL; $plugin_id = $entity_element['data-entity-embed-display']; $plugin_settings = $entity_element['data-entity-embed-settings'] ?: array(); $plugin_settings = $entity_element['data-entity-embed-display-settings'] ?: array(); $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $plugin_settings); $display->setContextValue('entity', $entity); $display->setAttributes($entity_element); Loading @@ -596,7 +596,7 @@ class EntityEmbedDialog extends FormBase { * The form state. */ public function updatePluginConfigurationForm(array &$form, FormStateInterface $form_state) { return $form['attributes']['data-entity-embed-settings']; return $form['attributes']['data-entity-embed-display-settings']; } /** Loading Loading @@ -732,7 +732,7 @@ class EntityEmbedDialog extends FormBase { ->loadByProperties(['uuid' => $entity_element['data-entity-uuid']]); $entity = current($entity); $plugin_id = $entity_element['data-entity-embed-display']; $plugin_settings = $entity_element['data-entity-embed-settings'] ?: array(); $plugin_settings = $entity_element['data-entity-embed-display-settings'] ?: array(); $display = $this->entityEmbedDisplayManager->createInstance($plugin_id, $plugin_settings); $display->setContextValue('entity', $entity); $display->setAttributes($entity_element); Loading @@ -750,8 +750,8 @@ class EntityEmbedDialog extends FormBase { } else { // Serialize entity embed settings to JSON string. if (!empty($values['attributes']['data-entity-embed-settings'])) { $values['attributes']['data-entity-embed-settings'] = Json::encode($values['attributes']['data-entity-embed-settings']); if (!empty($values['attributes']['data-entity-embed-display-settings'])) { $values['attributes']['data-entity-embed-display-settings'] = Json::encode($values['attributes']['data-entity-embed-display-settings']); } // Filter out empty attributes. Loading