You are here

function template_preprocess_filefield_sources_element in FileField Sources 8

Theme the display of the source element.

File

./filefield_sources.module, line 604
Extend FileField to allow files from multiple sources.

Code

function template_preprocess_filefield_sources_element(&$variables) {
  $element = $variables['element'];
  $source_id = $element['#source_id'];
  $method = isset($element['#method']) ? $element['#method'] : 'element';
  $extra_variables = isset($element['#variables']) ? $element['#variables'] : [];
  $sources = filefield_sources_info();
  if (isset($sources[$source_id]['class'])) {
    $callback = [
      $sources[$source_id]['class'],
      $method,
    ];
    if (is_callable($callback)) {
      $variables = array_merge($variables, $extra_variables);
      $variables['rendered_element'] = call_user_func_array($callback, [
        $variables,
      ]);
    }
  }
  return '';
}