Commit def09af6 authored by Wim Leers's avatar Wim Leers Committed by phenaproxima

Issue #2752253 by Wim Leers, marcoscano: Document correct...

Issue #2752253 by Wim Leers, marcoscano: Document correct filter_html_image_secure + filter_align + filter_caption + entity_embed filters order, write tests, and ensure correct by default
parent e2d14db6
......@@ -7,6 +7,7 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_help().
......@@ -85,3 +86,45 @@ function entity_embed_entity_embed_display_plugins_for_context_alter(array &$def
unset($definitions['entity_reference:entity_reference_entity_view']);
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function entity_embed_form_filter_format_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// Add an additional validate callback so we can ensure the order of filters
// is correct.
$form['#validate'][] = 'entity_embed_filter_format_edit_form_validate';
}
/**
* Validate callback to ensure order of filters does not break anything.
*/
function entity_embed_filter_format_edit_form_validate($form, FormStateInterface $form_state) {
// This validate handler is not applicable when using the 'Configure' button.
if ($form_state->getTriggeringElement()['#name'] === 'editor_configure') {
return;
}
$filters = $form_state->getValue('filters');
$get_filter_label = function ($filter_plugin_id) use ($form) {
return (string) $form['filters']['order'][$filter_plugin_id]['filter']['#markup'];
};
// Ensure the "entity_embed" filter is set to run before "filter_align" and
// "filter_caption".
if (isset($filters['entity_embed']['weight'])) {
if (isset($filters['filter_align']['weight']) && $filters['filter_align']['weight'] <= $filters['entity_embed']['weight']) {
$form_state->setErrorByName('filters', t('The %entity-embed-filter-label filter needs to be placed before the %align-filter-label filter.', [
'%entity-embed-filter-label' => $get_filter_label('entity_embed'),
'%align-filter-label' => $get_filter_label('filter_align')
]));
}
if (isset($filters['filter_caption']['weight']) && $filters['filter_caption']['weight'] <= $filters['entity_embed']['weight']) {
$form_state->setErrorByName('filters', t('The %entity-embed-filter-label filter needs to be placed before the %caption-filter-label filter.', [
'%entity-embed-filter-label' => $get_filter_label('entity_embed'),
'%caption-filter-label' => $get_filter_label('filter_caption')
]));
}
}
}
......@@ -22,7 +22,7 @@ use Drupal\embed\DomHelperTrait;
* @Filter(
* id = "entity_embed",
* title = @Translation("Display embedded entities"),
* description = @Translation("Embeds entities using data attributes: data-entity-type, data-entity-uuid, and data-view-mode."),
* description = @Translation("Embeds entities using data attributes: data-entity-type, data-entity-uuid, and data-view-mode. If used in conjunction with the 'Align/Caption' filters, make sure this filter is configured to run before them."),
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE
* )
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment