You are here

function vsf_wysiwyg_field_attach_presave in Visual select file 7

Implements hook_field_attach_presave().

Known issues:

  • Files in revisions. I don't know how File or Media handle this.

File

submodules/vsf_wysiwyg/vsf_wysiwyg.module, line 173

Code

function vsf_wysiwyg_field_attach_presave($entity_type, $entity) {
  $check_always = variable_get('vsf_wysiwyg_check_unchanged_fields', VSF_DEFAULT_CHECK_UNCHANGED_FIELDS);
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  $fields = _vsf_wysiwyg_get_text_format_fields($entity_type, $bundle);

  // Parse ALL text_format field values to find used fids, by public uri, by path.
  $fids = array();
  foreach ($fields as $field_name) {
    foreach ((array) @$entity->{$field_name} as $langcode => $items) {
      foreach ($items as $delta => $item) {
        $old_value = @$entity->original->{$field_name}[$langcode][$delta]['value'];
        $value = @$item['value'];
        if ($check_always || $old_value != $value) {
          _vsf_wysiwyg_parse($fids, $value);
        }
      }
    }
  }
  ksort($fids, SORT_NUMERIC);
  $entity->vsf_wysiwyg_fids = $fids;
}