function image_replace_form_field_config_edit_form_element_validate in Image Replace 8
Form element validation callback.
Displays a warning when replacement mapping is changed for fields with existing content.
1 string reference to 'image_replace_form_field_config_edit_form_element_validate'
- image_replace_form_field_config_edit_form_alter in ./
image_replace.module - Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
File
- ./
image_replace.module, line 65 - Provides an image style effect replacing the whole image with another one.
Code
function image_replace_form_field_config_edit_form_element_validate($element, &$form_state, $form) {
$field = $form_state
->getFormObject()
->getEntity();
$field_storage = FieldStorageConfig::loadByName($field
->getTargetEntityTypeId(), $field
->getName());
if ($field_storage
->hasData()) {
$changed = FALSE;
foreach (array_keys(_image_replace_style_options()) as $image_style) {
$current_value = $element['image_style_map'][$image_style]['source_field']['#default_value'];
$new_value = $element['image_style_map'][$image_style]['source_field']['#value'];
if (!(empty($current_value) && empty($new_value)) && $current_value != $new_value) {
$changed = TRUE;
break;
}
}
if ($changed) {
$messenger = \Drupal::messenger();
$messenger
->addWarning(t('The image replacement settings have been modified. As a result, it is necessary to rebuild the image replacement mapping for existing content. Note: The replacement mapping is updated automatically when saving an entity. Content can be resaved in bulk using the <em>save content</em> of the <a href="@content_url">administrative interface</a>', [
'@content_url' => '/admin/content',
]));
$messenger
->addWarning(t('Also note that images already might be cached in the browser or by any intermediate HTTP cache. On live sites the only way to force browsers to redownload a cached image is to reupload the image with a different name.'));
}
}
}