Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Allow drupal-entity elements to be inline #200

Open
wants to merge 4 commits into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/install/entity_embed.settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inline: false
8 changes: 8 additions & 0 deletions config/schema/entity_embed.schema.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Schema for the configuration files of the Entity Embed module.

entity_embed.settings:
type: config_object
label: 'Entity Embed settings'
mapping:
inline:
type: boolean
label: 'Allow inline embedded entities'

embed.embed_type_settings.entity:
type: mapping
label: 'Schema for the entity embed type additions to an embed button entity'
Expand Down
5 changes: 3 additions & 2 deletions js/plugins/drupalentity/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
var dtd = CKEDITOR.dtd, tagName;
dtd['drupal-entity'] = {'#': 1};
// Register drupal-entity element as allowed child, in each tag that can
// contain a div element.
// contain a div or img element (if inline embedding is turned on in the
// settings).
for (tagName in dtd) {
if (dtd[tagName].div) {
if (dtd[tagName].div || (dtd[tagName].img && editor.config.DrupalEntity_inline)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider on !!CKEDITOR.dtd.$inline[tagName] instead of img.

dtd[tagName]['drupal-entity'] = 1;
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/Plugin/CKEditorPlugin/DrupalEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Drupal\editor\Entity\Editor;
use Drupal\embed\EmbedButtonInterface;
use Drupal\embed\EmbedCKEditorPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Defines the "drupalentity" plugin.
Expand All @@ -22,6 +23,17 @@
*/
class DrupalEntity extends EmbedCKEditorPluginBase {

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$configuration['inline'] = $container->get('config.factory')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to have this configurable per-button.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's going to be possible to make it configurable per button. The reason being that making drupal-entity elements inline requires changing the DTD of the editor instance, which will take effect for the entire editor, regardless of how many different embed buttons are loaded into it. It's intrinsically a per-editor thing, not a per-button thing. But maybe I'm misunderstanding you -- what did you have in mind?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow that's quite some limitation of CKEditor then...

So if we need to limit this per button / entity type, we would need to have different tags. We can NOT depend on classes / attributes in the DTD. But using multiple tags is also a mismatch to the current filter approach - it would need extra configuration and changing it contains risk stale data.

How about considering an autogenerated (optional?) "drupal-entity-TYPE" tag that would allow specific DTDs? Yeah quite some change / added complexity in the filter..

->get('entity_embed.settings')
->get('inline');

return parent::create($container, $configuration, $plugin_id, $plugin_definition);
}

/**
* {@inheritdoc}
*/
Expand All @@ -46,6 +58,7 @@ public function getConfig(Editor $editor) {
'DrupalEntity_dialogTitleAdd' => t('Insert entity'),
'DrupalEntity_dialogTitleEdit' => t('Edit entity'),
'DrupalEntity_buttons' => $this->getButtons(),
'DrupalEntity_inline' => $this->configuration['inline'],
);
}

Expand Down