You are here

function vsf_wysiwyg_save_file_usage_submit in Visual select file 7

Submit handler for all File Usage loving forms with VSF WYSIWYG elements.

1 string reference to 'vsf_wysiwyg_save_file_usage_submit'
YOURMODULE_custom_form in ./visual_select_file.api.php
Some custom form on your website, maybe global, or per-domain, or not.

File

submodules/vsf_wysiwyg/vsf_wysiwyg.module, line 116

Code

function vsf_wysiwyg_save_file_usage_submit($form, &$form_state) {
  foreach ($form_state['vsf_wysiwyg_file_usage'] as $type => $instances) {
    foreach ($instances as $id => $files) {

      // Make sure this id is a valid 32 bit int. {file_usage} expects it, but VSF doesn't want to
      // force it.
      if ((string) (int) $id !== (string) $id) {
        $id = sprintf('%u', crc32($id));
      }

      // Delete all, for this instance.
      db_delete('file_usage')
        ->condition('module', 'vsf_wysiwyg')
        ->condition('type', $type)
        ->condition('id', $id)
        ->execute();

      // Add per found fid.
      foreach ($files as $fid => $count) {
        $file = (object) compact('fid');
        file_usage_add($file, 'vsf_wysiwyg', $type, $id, $count);
      }
    }
  }
}