This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Decouple engine from UI #189
Open
phenaproxima
wants to merge
3
commits into
drupal-media:8.x-1.x
Choose a base branch
from
phenaproxima:decouple_engine
base: 8.x-1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* @file | ||
* Drupal Entity embed plugin. | ||
*/ | ||
|
||
(function ($, Drupal, CKEDITOR) { | ||
|
||
"use strict"; | ||
|
||
CKEDITOR.plugins.add('drupalentity', { | ||
// This plugin requires the Widgets System defined in the 'widget' plugin. | ||
requires: 'widget', | ||
|
||
// The plugin initialization logic goes inside this method. | ||
beforeInit: function (editor) { | ||
// Configure CKEditor DTD for custom drupal-entity element. | ||
// @see https://www.drupal.org/node/2448449#comment-9717735 | ||
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. | ||
for (tagName in dtd) { | ||
if (dtd[tagName].div) { | ||
dtd[tagName]['drupal-entity'] = 1; | ||
} | ||
} | ||
|
||
// Register the entity embed widget. | ||
editor.widgets.add('drupalentity', { | ||
// Minimum HTML which is required by this widget to work. | ||
allowedContent: 'drupal-entity[*]', | ||
requiredContent: 'drupal-entity[*]', | ||
|
||
// Simply recognize the element as our own. The inner markup if fetched | ||
// and inserted the init() callback, since it requires the actual DOM | ||
// element. | ||
upcast: function (element) { | ||
var attributes = element.attributes; | ||
if (attributes['data-entity-type'] === undefined || (attributes['data-entity-id'] === undefined && attributes['data-entity-uuid'] === undefined) || (attributes['data-view-mode'] === undefined && attributes['data-entity-embed-display'] === undefined)) { | ||
return; | ||
} | ||
// Generate an ID for the element, so that we can use the Ajax | ||
// framework. | ||
element.attributes.id = generateEmbedId(); | ||
return element; | ||
}, | ||
|
||
// Fetch the rendered entity. | ||
init: function () { | ||
var element = this.element; | ||
var $element = $(element.$); | ||
// Use the Ajax framework to fetch the HTML, so that we can retrieve | ||
// out-of-band assets (JS, CSS...). | ||
var entityEmbedPreview = new Drupal.ajax({ | ||
base: $element.attr('id'), | ||
element: $element, | ||
url: Drupal.url('embed/preview/' + editor.config.drupal.format + '?' + $.param({ | ||
value: element.getOuterHtml() | ||
})), | ||
progress: {type: 'none'}, | ||
// Use a custom event to trigger the call. | ||
event: 'entity_embed_dummy_event' | ||
}); | ||
entityEmbedPreview.execute(); | ||
}, | ||
|
||
// Downcast the element. | ||
downcast: function (element) { | ||
// Only keep the wrapping element. | ||
element.setHtml(''); | ||
// Remove the auto-generated ID. | ||
delete element.attributes.id; | ||
return element; | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
/** | ||
* Generates unique HTML IDs for the widgets. | ||
* | ||
* @returns {string} | ||
*/ | ||
function generateEmbedId() { | ||
if (typeof generateEmbedId.counter == 'undefined') { | ||
generateEmbedId.counter = 0; | ||
} | ||
return 'entity-embed-' + generateEmbedId.counter++; | ||
} | ||
|
||
})(jQuery, Drupal, CKEDITOR); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\entity_embed\Plugin\CKEditorPlugin\DrupalEntityButton. | ||
*/ | ||
|
||
namespace Drupal\entity_embed\Plugin\CKEditorPlugin; | ||
|
||
use Drupal\editor\Entity\Editor; | ||
use Drupal\embed\EmbedButtonInterface; | ||
use Drupal\embed\EmbedCKEditorPluginBase; | ||
|
||
/** | ||
* Defines the "drupalentity_button" plugin. | ||
* | ||
* @CKEditorPlugin( | ||
* id = "drupalentity_button", | ||
* label = @Translation("Entity"), | ||
* embed_type_id = "entity" | ||
* ) | ||
*/ | ||
class DrupalEntityButton extends EmbedCKEditorPluginBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getButton(EmbedButtonInterface $embed_button) { | ||
$button = parent::getButton($embed_button); | ||
$button['entity_type'] = $embed_button->getTypeSetting('entity_type'); | ||
return $button; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDependencies(Editor $editor) { | ||
return ['drupalentity']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFile() { | ||
return drupal_get_path('module', 'entity_embed') . '/js/plugins/drupalentity/plugin.js'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfig(Editor $editor) { | ||
return array( | ||
'DrupalEntity_dialogTitleAdd' => t('Insert entity'), | ||
'DrupalEntity_dialogTitleEdit' => t('Edit entity'), | ||
'DrupalEntity_buttons' => $this->getButtons(), | ||
); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems odd that this would still extend EmbedCKEditorPluginBase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is strange indeeed.