Commit 7d05e583 authored by alexpott's avatar alexpott

Revert "Issue #2510380 by Wim Leers, DuaelFr, mlewand, quicksketch, Reinmar,...

Revert "Issue #2510380 by Wim Leers, DuaelFr, mlewand, quicksketch, Reinmar, oleq: Images cannot be linked in CKEditor"

This reverts commit 2d342c0f.
parent 2d342c0f
...@@ -65,11 +65,14 @@ ...@@ -65,11 +65,14 @@
} }
widgetDefinition.allowedContent = new CKEDITOR.style(allowedContentDefinition); widgetDefinition.allowedContent = new CKEDITOR.style(allowedContentDefinition);
// Override the 'link' part, to completely disable image2's link
// support: http://dev.ckeditor.com/ticket/11341.
widgetDefinition.parts.link = 'This is a nonsensical selector to disable this functionality completely';
// Override downcast(): since we only accept <img> in our upcast method, // Override downcast(): since we only accept <img> in our upcast method,
// the element is already correct. We only need to update the element's // the element is already correct. We only need to update the element's
// data-entity-uuid attribute. // data-entity-uuid attribute.
widgetDefinition.downcast = function (element) { widgetDefinition.downcast = function (element) {
element.attributes['data-entity-type'] = this.data['data-entity-type'];
element.attributes['data-entity-uuid'] = this.data['data-entity-uuid']; element.attributes['data-entity-uuid'] = this.data['data-entity-uuid'];
}; };
...@@ -173,18 +176,6 @@ ...@@ -173,18 +176,6 @@
return widget; return widget;
}; };
}; };
var originalInit = widgetDefinition.init;
widgetDefinition.init = function () {
originalInit.call(this);
// Update data.link object with attributes if the link has been
// discovered.
// @see plugins/image2/plugin.js/init() in CKEditor; this is similar.
if (this.parts.link) {
this.setData('link', CKEDITOR.plugins.link.parseLinkAttributes(editor, this.parts.link));
}
};
}); });
// Add a widget#edit listener to every instance of image2 widget in order // Add a widget#edit listener to every instance of image2 widget in order
...@@ -242,86 +233,25 @@ ...@@ -242,86 +233,25 @@
} }
}, },
// Disable image2's integration with the link/drupallink plugins: don't
// allow the widget itself to become a link. Support for that may be added
// by an text filter that adds a data- attribute specifically for that.
afterInit: function (editor) { afterInit: function (editor) {
linkCommandIntegrator(editor); if (editor.plugins.drupallink) {
} var cmd = editor.getCommand('drupallink');
// Needs to be refreshed on selection changes.
}); cmd.contextSensitive = 1;
// Disable command and cancel event when the image widget is selected.
/** cmd.on('refresh', function (evt) {
* Integrates the drupalimage widget with the drupallink plugin. var widget = editor.widgets.focused;
* if (widget && widget.name === 'image') {
* Makes images linkable. this.setState(CKEDITOR.TRISTATE_DISABLED);
* evt.cancel();
* @param {CKEDITOR.editor} editor }
* A CKEditor instance. });
*/
function linkCommandIntegrator(editor) {
// Nothing to integrate with if the drupallink plugin is not loaded.
if (!editor.plugins.drupallink) {
return;
}
// Override default behaviour of 'drupalunlink' command.
editor.getCommand('drupalunlink').on('exec', function (evt) {
var widget = getFocusedWidget(editor);
// Override 'drupalunlink' only when link truly belongs to the widget. If
// wrapped inline widget in a link, let default unlink work.
// @see https://dev.ckeditor.com/ticket/11814
if (!widget || !widget.parts.link) {
return;
}
widget.setData('link', null);
// Selection (which is fake) may not change if unlinked image in focused
// widget, i.e. if captioned image. Let's refresh command state manually
// here.
this.refresh(editor, editor.elementPath());
evt.cancel();
});
// Override default refresh of 'drupalunlink' command.
editor.getCommand('drupalunlink').on('refresh', function (evt) {
var widget = getFocusedWidget(editor);
if (!widget) {
return;
} }
// Note that widget may be wrapped in a link, which
// does not belong to that widget (#11814).
this.setState(widget.data.link || widget.wrapper.getAscendant('a') ?
CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED);
evt.cancel();
});
}
/**
* Gets the focused widget, if of the type specific for this plugin.
*
* @param {CKEDITOR.editor} editor
* A CKEditor instance.
*
* @return {?CKEDITOR.plugins.widget}
* The focused image2 widget instance, or null.
*/
function getFocusedWidget(editor) {
var widget = editor.widgets.focused;
if (widget && widget.name === 'image') {
return widget;
} }
return null; });
}
// Expose an API for other plugins to interact with drupalimage widgets.
CKEDITOR.plugins.drupalimage = {
getFocusedWidget: getFocusedWidget
};
})(jQuery, Drupal, CKEDITOR); })(jQuery, Drupal, CKEDITOR);
...@@ -71,9 +71,10 @@ ...@@ -71,9 +71,10 @@
// data-caption attributes. // data-caption attributes.
var originalDowncast = widgetDefinition.downcast; var originalDowncast = widgetDefinition.downcast;
widgetDefinition.downcast = function (element) { widgetDefinition.downcast = function (element) {
var img = findElementByName(element, 'img'); var img = originalDowncast.call(this, element);
originalDowncast.call(this, img); if (!img) {
img = findElementByName(element, 'img');
}
var caption = this.editables.caption; var caption = this.editables.caption;
var captionHtml = caption && caption.getData(); var captionHtml = caption && caption.getData();
var attrs = img.attributes; var attrs = img.attributes;
...@@ -90,14 +91,10 @@ ...@@ -90,14 +91,10 @@
attrs['data-align'] = this.data.align; attrs['data-align'] = this.data.align;
} }
} }
attrs['data-entity-type'] = this.data['data-entity-type'];
attrs['data-entity-uuid'] = this.data['data-entity-uuid'];
// If img is wrapped with a link, we want to return that link. return img;
if (img.parent.name === 'a') {
return img.parent;
}
else {
return img;
}
}; };
// We want to upcast <img> elements to a DOM structure required by the // We want to upcast <img> elements to a DOM structure required by the
...@@ -118,11 +115,6 @@ ...@@ -118,11 +115,6 @@
element = originalUpcast.call(this, element, data); element = originalUpcast.call(this, element, data);
var attrs = element.attributes; var attrs = element.attributes;
if (element.parent.name === 'a') {
element = element.parent;
}
var retElement = element; var retElement = element;
var caption; var caption;
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
modes: {wysiwyg: 1}, modes: {wysiwyg: 1},
canUndo: true, canUndo: true,
exec: function (editor) { exec: function (editor) {
var drupalImageUtils = CKEDITOR.plugins.drupalimage;
var focusedImageWidget = drupalImageUtils && drupalImageUtils.getFocusedWidget(editor);
var linkElement = getSelectedLink(editor); var linkElement = getSelectedLink(editor);
var linkDOMElement = null; var linkDOMElement = null;
...@@ -58,30 +56,9 @@ ...@@ -58,30 +56,9 @@
existingValues[attributeName] = linkElement.data('cke-saved-' + attributeName) || attribute.nodeValue; existingValues[attributeName] = linkElement.data('cke-saved-' + attributeName) || attribute.nodeValue;
} }
} }
// Or, if an image widget is focused, we're editing a link wrapping
// an image widget.
else if (focusedImageWidget && focusedImageWidget.data.link) {
var url = focusedImageWidget.data.link.url;
existingValues.href = url.protocol + url.url;
}
// Prepare a save callback to be used upon saving the dialog. // Prepare a save callback to be used upon saving the dialog.
var saveCallback = function (returnValues) { var saveCallback = function (returnValues) {
// If an image widget is focused, we're not editing an independent
// link, but we're wrapping an image widget in a link.
if (focusedImageWidget) {
var urlMatch = returnValues.attributes.href.match(urlRegex);
focusedImageWidget.setData('link', {
type: 'url',
url: {
protocol: urlMatch[1],
url: urlMatch[2]
}
});
editor.fire('saveSnapshot');
return;
}
editor.fire('saveSnapshot'); editor.fire('saveSnapshot');
// Create a new link element if needed. // Create a new link element if needed.
...@@ -279,57 +256,4 @@ ...@@ -279,57 +256,4 @@
return null; return null;
} }
var urlRegex = /^((?:http|https):\/\/)?(.*)$/;
/**
* The image2 plugin is currently tightly coupled to the link plugin: it
* calls CKEDITOR.plugins.link.parseLinkAttributes().
*
* Drupal 8's CKEditor build doesn't include the 'link' plugin. Because it
* includes its own link plugin that integrates with Drupal's dialog system.
* So, to allow images to be linked, we need to duplicate the necessary subset
* of the logic.
*
* @todo Remove once we update to CKEditor 4.5.5.
* @see https://dev.ckeditor.com/ticket/13885
*/
CKEDITOR.plugins.link = CKEDITOR.plugins.link || {
parseLinkAttributes: function (editor, element) {
var href = (element && (element.data('cke-saved-href') || element.getAttribute('href'))) || '';
var urlMatch = href.match(urlRegex);
return {
type: 'url',
url: {
protocol: urlMatch[1],
url: urlMatch[2]
}
};
},
getLinkAttributes: function (editor, data) {
var set = {};
var protocol = (data.url && typeof data.url.protocol !== 'undefined') ? data.url.protocol : 'http://';
var url = (data.url && CKEDITOR.tools.trim(data.url.url)) || '';
set['data-cke-saved-href'] = (url.indexOf('/') === 0) ? url : protocol + url;
// Browser need the "href" fro copy/paste link to work. (#6641)
if (set['data-cke-saved-href']) {
set.href = set['data-cke-saved-href'];
}
// Remove all attributes which are not currently set.
var removed = {};
for (var s in set) {
if (set.hasOwnProperty(s)) {
delete removed[s];
}
}
return {
set: set,
removed: CKEDITOR.tools.objectKeys(removed)
};
}
};
})(jQuery, Drupal, drupalSettings, CKEDITOR); })(jQuery, Drupal, drupalSettings, CKEDITOR);
...@@ -55,17 +55,15 @@ public function process($text, $langcode) { ...@@ -55,17 +55,15 @@ public function process($text, $langcode) {
// Given the updated node and caption: re-render it with a caption, but // Given the updated node and caption: re-render it with a caption, but
// bubble up the value of the class attribute of the captioned element, // bubble up the value of the class attribute of the captioned element,
// this allows it to collaborate with e.g. the filter_align filter. // this allows it to collaborate with e.g. the filter_align filter.
$tag = $node->tagName;
$classes = $node->getAttribute('class'); $classes = $node->getAttribute('class');
$node->removeAttribute('class'); $node->removeAttribute('class');
$node = ($node->parentNode->tagName === 'a') ? $node->parentNode : $node;
$filter_caption = array( $filter_caption = array(
'#theme' => 'filter_caption', '#theme' => 'filter_caption',
// We pass the unsanitized string because this is a text format // We pass the unsanitized string because this is a text format
// filter, and after filtering, we always assume the output is safe. // filter, and after filtering, we always assume the output is safe.
// @see \Drupal\filter\Element\ProcessedText::preRenderText() // @see \Drupal\filter\Element\ProcessedText::preRenderText()
'#node' => FilteredMarkup::create($node->C14N()), '#node' => FilteredMarkup::create($node->C14N()),
'#tag' => $tag, '#tag' => $node->tagName,
'#caption' => $caption, '#caption' => $caption,
'#classes' => $classes, '#classes' => $classes,
); );
...@@ -80,7 +78,7 @@ public function process($text, $langcode) { ...@@ -80,7 +78,7 @@ public function process($text, $langcode) {
// Import the updated node from the new DOMDocument into the original // Import the updated node from the new DOMDocument into the original
// one, importing also the child nodes of the updated node. // one, importing also the child nodes of the updated node.
$updated_node = $dom->importNode($updated_node, TRUE); $updated_node = $dom->importNode($updated_node, TRUE);
// Finally, replace the original node with the new node. // Finally, replace the original image node with the new image node!
$node->parentNode->replaceChild($updated_node, $node); $node->parentNode->replaceChild($updated_node, $node);
} }
......
...@@ -184,13 +184,6 @@ function testCaptionFilter() { ...@@ -184,13 +184,6 @@ function testCaptionFilter() {
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAttachments()); $this->assertIdentical($attached_library, $output->getAttachments());
// Ensure the caption filter works for linked images.
$input = '<a href="http://example.com/llamas/are/awesome/but/kittens/are/cool/too"><img src="llama.jpg" data-caption="Loquacious llama!" /></a>';
$expected = '<figure role="group"><a href="http://example.com/llamas/are/awesome/but/kittens/are/cool/too"><img src="llama.jpg" /></a>' . "\n" . '<figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAttachments());
// So far we've tested that the caption filter works correctly. But we also // So far we've tested that the caption filter works correctly. But we also
// want to make sure that it works well in tandem with the "Limit allowed // want to make sure that it works well in tandem with the "Limit allowed
// HTML tags" filter, which it is typically used with. // HTML tags" filter, which it is typically used with.
...@@ -308,13 +301,6 @@ function testAlignAndCaptionFilters() { ...@@ -308,13 +301,6 @@ function testAlignAndCaptionFilters() {
$output = $test($input); $output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText()); $this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAttachments()); $this->assertIdentical($attached_library, $output->getAttachments());
// Ensure both filters together work for linked images.
$input = '<a href="http://example.com/llamas/are/awesome/but/kittens/are/cool/too"><img src="llama.jpg" data-caption="Loquacious llama!" data-align="center" /></a>';
$expected = '<figure role="group" class="align-center"><a href="http://example.com/llamas/are/awesome/but/kittens/are/cool/too"><img src="llama.jpg" /></a>' . "\n" . '<figcaption>Loquacious llama!</figcaption></figure>';
$output = $test($input);
$this->assertIdentical($expected, $output->getProcessedText());
$this->assertIdentical($attached_library, $output->getAttachments());
} }
/** /**
......
...@@ -170,20 +170,17 @@ function simpletest_run_tests($test_list) { ...@@ -170,20 +170,17 @@ function simpletest_run_tests($test_list) {
* @param $unescaped_test_classnames * @param $unescaped_test_classnames
* An array of test class names, including full namespaces, to be passed as * An array of test class names, including full namespaces, to be passed as
* a regular expression to PHPUnit's --filter option. * a regular expression to PHPUnit's --filter option.
* @param int $status
* (optional) The exit status code of the PHPUnit process will be assigned to
* this variable.
* *
* @return array * @return array
* The parsed results of PHPUnit's JUnit XML output, in the format of * The parsed results of PHPUnit's JUnit XML output, in the format of
* {simpletest}'s schema. * {simpletest}'s schema.
*/ */
function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames, &$status = NULL) { function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames) {
$phpunit_file = simpletest_phpunit_xml_filepath($test_id); $phpunit_file = simpletest_phpunit_xml_filepath($test_id);
simpletest_phpunit_run_command($unescaped_test_classnames, $phpunit_file, $status); $ret = simpletest_phpunit_run_command($unescaped_test_classnames, $phpunit_file);
// A $status of 0 = passed test, 1 = failed test, > 1 indicates segfault // A return value of 0 = passed test, 1 = failed test, > 1 indicates segfault
// timeout, or other type of failure. // timeout, or other type of failure.
if ($status > 1) { if ($ret > 1) {
// Something broke during the execution of phpunit. // Something broke during the execution of phpunit.
// Return an error record of all failed classes. // Return an error record of all failed classes.
$rows[] = [ $rows[] = [
...@@ -254,14 +251,11 @@ function simpletest_phpunit_configuration_filepath() { ...@@ -254,14 +251,11 @@ function simpletest_phpunit_configuration_filepath() {
* a regular expression to PHPUnit's --filter option. * a regular expression to PHPUnit's --filter option.
* @param string $phpunit_file * @param string $phpunit_file
* A filepath to use for PHPUnit's --log-junit option. * A filepath to use for PHPUnit's --log-junit option.
* @param int $status
* (optional) The exit status code of the PHPUnit process will be assigned to
* this variable.
* *
* @return string * @return string
* The results as returned by exec(). * The results as returned by exec().
*/ */
function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL) { function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file) {
// Setup an environment variable containing the database connection so that // Setup an environment variable containing the database connection so that
// functional tests can connect to the database. // functional tests can connect to the database.
putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl()); putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl());
...@@ -298,8 +292,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun ...@@ -298,8 +292,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
// exec in a subshell so that the environment is isolated when running tests // exec in a subshell so that the environment is isolated when running tests
// via the simpletest UI. // via the simpletest UI.
$ret = exec(join($command, " "), $output, $status); exec(join($command, " "), $output, $ret);
chdir($old_cwd); chdir($old_cwd);
putenv('SIMPLETEST_DB='); putenv('SIMPLETEST_DB=');
return $ret; return $ret;
......
...@@ -23,68 +23,46 @@ ...@@ -23,68 +23,46 @@
// Restricting the chunk of queries prevents memory exhaustion. // Restricting the chunk of queries prevents memory exhaustion.
const SIMPLETEST_SCRIPT_SQLITE_VARIABLE_LIMIT = 350; const SIMPLETEST_SCRIPT_SQLITE_VARIABLE_LIMIT = 350;
const SIMPLETEST_SCRIPT_EXIT_SUCCESS = 0;
const SIMPLETEST_SCRIPT_EXIT_FAILURE = 1;
const SIMPLETEST_SCRIPT_EXIT_EXCEPTION = 2;
// Set defaults and get overrides. // Set defaults and get overrides.
list($args, $count) = simpletest_script_parse_args(); list($args, $count) = simpletest_script_parse_args();
if ($args['help'] || $count == 0) { if ($args['help'] || $count == 0) {
simpletest_script_help(); simpletest_script_help();
exit(($count == 0) ? SIMPLETEST_SCRIPT_EXIT_FAILURE : SIMPLETEST_SCRIPT_EXIT_SUCCESS); exit;
} }
simpletest_script_init(); simpletest_script_init();
try { $request = Request::createFromGlobals();
$request = Request::createFromGlobals(); $kernel = TestRunnerKernel::createFromRequest($request, $autoloader);
$kernel = TestRunnerKernel::createFromRequest($request, $autoloader); $kernel->prepareLegacyRequest($request);
$kernel->prepareLegacyRequest($request);
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
if ($args['execute-test']) { if ($args['execute-test']) {
simpletest_script_setup_database(); simpletest_script_setup_database();
simpletest_script_run_one_test($args['test-id'], $args['execute-test']); simpletest_script_run_one_test($args['test-id'], $args['execute-test']);
// Sub-process exited already; this is just for clarity. // Sub-process exited already; this is just for clarity.
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS); exit;
} }
if ($args['list']) { if ($args['list']) {
// Display all available tests. // Display all available tests.
echo "\nAvailable test groups & classes\n"; echo "\nAvailable test groups & classes\n";
echo "-------------------------------\n\n"; echo "-------------------------------\n\n";
try { $groups = simpletest_test_get_all($args['module']);
$groups = simpletest_test_get_all($args['module']);
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
foreach ($groups as $group => $tests) { foreach ($groups as $group => $tests) {
echo $group . "\n"; echo $group . "\n";
foreach ($tests as $class => $info) { foreach ($tests as $class => $info) {
echo " - $class\n"; echo " - $class\n";
} }
} }
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS); exit;
} }
simpletest_script_setup_database(TRUE); simpletest_script_setup_database(TRUE);
if ($args['clean']) { if ($args['clean']) {
// Clean up left-over tables and directories. // Clean up left-over tables and directories.
try { simpletest_clean_environment();
simpletest_clean_environment();
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
}
echo "\nEnvironment cleaned.\n"; echo "\nEnvironment cleaned.\n";
// Get the status messages and print them. // Get the status messages and print them.
...@@ -92,7 +70,7 @@ ...@@ -92,7 +70,7 @@
foreach ($messages['status'] as $text) { foreach ($messages['status'] as $text) {
echo " - " . $text . "\n"; echo " - " . $text . "\n";
} }
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS); exit;
} }
$test_list = simpletest_script_get_test_list(); $test_list = simpletest_script_get_test_list();
...@@ -107,7 +85,7 @@ ...@@ -107,7 +85,7 @@
} }
// Execute tests. // Execute tests.
$status = simpletest_script_execute_batch($tests_to_run); simpletest_script_execute_batch($tests_to_run);
// Stop the timer. // Stop the timer.
simpletest_script_reporter_timer_stop(); simpletest_script_reporter_timer_stop();
...@@ -126,17 +104,11 @@ ...@@ -126,17 +104,11 @@
// Clean up all test results. // Clean up all test results.
if (!$args['keep-results']) { if (!$args['keep-results']) {
try { simpletest_clean_results_table();
simpletest_clean_results_table();
}
catch (Exception $e) {
echo (string) $e;
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);