You are here

function custom_formatters_coder_review in Custom Formatters 7.2

Ajax callback for Custom Formatters Coder Review integration.

Parameters

array $form: The form api array.

array $form_state: The form state array.

Return value

mixed The Coder Review result render array.

1 string reference to 'custom_formatters_coder_review'
coder_review_custom_formatters_form_alter_alter in includes/coder_review.inc
Implements hook_custom_formatters_form_alter_alter().

File

includes/coder_review.inc, line 58
Coder Review module integration.

Code

function custom_formatters_coder_review(&$form, $form_state) {
  $directory = 'public://custom_formatters/coder_review';
  if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
    global $base_url;
    $md5 = md5($form_state['values']['code']);
    file_unmanaged_save_data("<?php\n/**\n * @file\n */\n\n{$form_state['values']['code']}", "{$directory}/{$md5}.php", FILE_EXISTS_REPLACE);
    $file = str_replace($base_url . base_path(), '', file_create_url("{$directory}/{$md5}.php"));
    $form_state = array(
      'storage' => array(
        'coder_reviews' => $form_state['values']['coder_reviews'],
        'coder_severity' => $form_state['values']['coder_severity'],
        'coder_file_list' => $file,
        'coder_files' => 1,
      ),
    );
    $review = coder_review_page_form(array(), $form_state, 'files');
    $form['engine']['coder_review']['review'][$file] = $review[$file]['output'];
    foreach ($form['engine']['coder_review']['review'][$file]['#results'] as &$result) {

      // Adjust the line numbering.
      $result = preg_replace('/\\/\\>Line (\\d+):(.*?<pre>)/e', '"/>Line " . ($1 - 5) . ":$2"', $result);
    }
    unset($form['engine']['coder_review']['review'][$file]['#filename']);
    file_unmanaged_delete("{$directory}/{$md5}.php");
  }
  drupal_get_messages(NULL, TRUE);
  return $form['engine']['coder_review']['review'];
}