You are here

function swftools_admin_extensions_submit in SWF Tools 6.3

Explodes a string of file extensions and converts them back in to an array.

On the admin page we show the user a list of actions and allow them to associate extensions with each one. But when it comes to generating content we will have the extension and we need to discover the action.

What we do in this submit handler is crunch the settings array so it is available with extensions as key under the variable swftools_actions. So we actually store this data twice,

1 string reference to 'swftools_admin_extensions_submit'
swftools_admin_handling_form in includes/swftools.admin.inc

File

includes/swftools.admin.inc, line 783
Configuration settings for SWF Tools.

Code

function swftools_admin_extensions_submit($form, &$form_state) {

  // Explode the separate list back to an array of strings
  foreach ($form_state['values']['swftools_extensions'] as $action => $extensions) {

    // Explode in to separate pieces
    $temp = explode(' ', $extensions);

    // Trim white space
    $temp = array_map('trim', $temp);

    // Unset empty elements
    $temp = array_filter($temp);

    // Store the result
    $form_state['values']['swftools_extensions'][$action] = $temp;
  }

  // For use in a page it's easier to have things organised by extension
  $actions = array();
  foreach ($form_state['values']['swftools_extensions'] as $action => $extensions) {

    // TODO: array_fill_keys() is only available in PHP >= 5.2.0 - ok for D7
    // $actions += array_fill_keys($extensions, $action);
    foreach ($extensions as $extension) {
      $actions[$extension] = $action;
    }
  }

  // Attach array of extension - action pairs to swftools_actions ready for saving
  $form_state['values']['swftools_actions'] = $actions;
}