You are here

function image_replace_form_field_ui_field_edit_form_element_validate in Image Replace 7

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_ui_field_edit_form_element_validate'
image_replace_form_field_ui_field_edit_form_alter in ./image_replace.module
Implements hook_form_FORM_ID_alter().

File

./image_replace.module, line 114
Provides an image style effect replacing the whole image with another one.

Code

function image_replace_form_field_ui_field_edit_form_element_validate($element, &$form_state, $form) {
  if (field_has_data($form['#field'])) {
    $changed = FALSE;
    foreach (_image_replace_style_options() as $image_style => $label) {
      $current_value = $element[$image_style]['source_field']['#default_value'];
      $new_value = $element[$image_style]['source_field']['#value'];
      if (!(empty($current_value) && empty($new_value)) && $current_value != $new_value) {
        $changed = TRUE;
        break;
      }
    }
    if ($changed) {
      $replacements = array(
        '@vbo_project_url' => 'https://drupal.org/project/views_bulk_operations',
        '@rules_project_url' => 'https://drupal.org/project/rules',
        '@admin_url' => url('admin/config/media/image-replace-rebuild-node', array(
          'query' => array(
            'type_op' => 'in',
            'type[]' => $form['#instance']['bundle'],
          ),
        )),
        '@media_url' => url('admin/config/media'),
      );
      $non_node_hint = t('If it is too cumbersome to track down all existing entities and resave them, it is suggested to build an administrative View using <a href="@vbo_project_url">Views Bulk Operations</a> and <a href="@rules_project_url">Rules</a>. Image Replace comes with such a View for content entities, which can serve as an example for other entity types.', $replacements);
      $hint_matrix[0][0] = $non_node_hint;
      $hint_matrix[0][1] = $non_node_hint;
      $hint_matrix[1][0] = t('If it is too cumbersome to track down all existing entities and resave them, it is suggested to install <a href="@vbo_project_url">Views Bulk Operations</a> and <a href="@rules_project_url">Rules</a>. Image Replace comes with an administrative View, which can be used to rebuild the image replacement mapping for existing content.', $replacements);
      $hint_matrix[1][1] = t('An <a href="@admin_url">administrative interface</a> capable of rebuilding the replacement mapping is part of the <a href="@media_url">Media configuration</a>', $replacements);
      $is_node = $form['#instance']['entity_type'] === 'node';
      $has_vbo = module_exists('views_bulk_operations') && module_exists('rules');
      $message = 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.');
      $message .= '<br>';
      $message .= $hint_matrix[$is_node][$has_vbo];
      $message .= '<br>';
      $message .= 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.');
      drupal_set_message($message, 'warning');
    }
  }
}