entity_embed.module | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/entity_embed.module b/entity_embed.module index 6f33ae1..361e5cb 100644 --- a/entity_embed.module +++ b/entity_embed.module @@ -107,17 +107,21 @@ function entity_embed_filter_format_edit_form_validate($form, FormStateInterface $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". - if (!empty($filters['filter_align']['weight']) - && !empty($filters['entity_embed']['weight']) - && ($filters['filter_align']['weight'] >= $filters['entity_embed']['weight'])) { - $form_state->setErrorByName('filters', t('The "Entity Embed" filter needs to be placed before the "Align images" filter.')); + if (isset($filters['filter_align']['weight']) + && isset($filters['entity_embed']['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')])); } // Ensure the "entity_embed" filter is set to run before "filter_caption". - if (!empty($filters['filter_caption']['weight']) - && !empty($filters['entity_embed']['weight']) - && ($filters['filter_caption']['weight'] >= $filters['entity_embed']['weight'])) { - $form_state->setErrorByName('filters', t('The "Entity Embed" filter needs to be placed before the "Caption images" filter.')); + if (isset($filters['filter_caption']['weight']) + && isset($filters['entity_embed']['weight']) + && ((int) $filters['filter_caption']['weight'] <= (int) $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_caption')])); } }