You are here

function _modernizr_api_list_clean in Modernizr 7.3

Same name and namespace in other branches
  1. 8 modernizr.module \_modernizr_api_list_clean()

Cleans up the array of tests to be unified.

Parameters

$raw_tests array: An array of tests provided by hook_modernizr_info.

Return value

array

1 call to _modernizr_api_list_clean()
modernizr_api_list in ./modernizr.module
Asks other Drupal modules which Modernizr tests they need.

File

./modernizr.module, line 736
Main module file for Modernizr

Code

function _modernizr_api_list_clean($raw_tests) {
  $clean_tests = array();
  foreach ($raw_tests as $module => $tests) {
    foreach ($tests as $name => $data) {

      // First, we check and correct if the tests have been added using indexed
      // arrays, fixing the name variable.
      if (is_int($name) && !is_array($data)) {

        // The test is stored as a simple array, therefore the data is the name.
        $name = $data;
        $data = array();
      }
      elseif (is_int($name) && is_array($data)) {

        // Still stored as a indexed array, but the data is an array.
        $name = $data['name'];
      }

      // Now, we add these tests to our array of cleaned up data.
      if (isset($clean_tests[$name])) {

        // We already have the test, we are just going to add our module name.
        $clean_tests[$name]['source'][] = $module;
      }
      else {

        // The test has not been marked, we are adding it to the array.
        $clean_tests[$name] = $data;
        $clean_tests[$name]['source'] = array(
          $module,
        );
      }
    }
  }

  // Cleaning up the data to ensure all data we need is present.
  foreach ($clean_tests as $name => $clean_test) {
    $data = array(
      'name' => $name,
      'desc' => _modernizr_get_desc($name),
      'docs' => '',
      'camiuse' => '',
    );
    $clean_tests[$name] = array_merge($data, $clean_test);
  }
  return $clean_tests;
}