You are here

function linkchecker_form_alter in Link checker 7

Same name and namespace in other branches
  1. 5.2 linkchecker.module \linkchecker_form_alter()
  2. 6.2 linkchecker.module \linkchecker_form_alter()

Implements hook_form_alter().

File

./linkchecker.module, line 994
This module periodically check links in given node types, blocks etc.

Code

function linkchecker_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {

    // Catch the custom block add/configure form and add custom submit handler.
    case 'block_add_block_form':

      // Add custom submit handler to custom block add form.
      $form['#submit'][] = 'linkchecker_block_custom_add_form_submit';
      break;
    case 'block_admin_configure':

      // When displaying the form, show the broken links warning.
      if (empty($form_state['input']) && is_numeric(arg(5))) {

        // Show a message on custom block edit page if a link check failed once
        // or more often.
        $ignore_response_codes = preg_split('/(\\r\\n?|\\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
        $links = db_query('SELECT ll.* FROM {linkchecker_block_custom} lb INNER JOIN {linkchecker_link} ll ON lb.lid = ll.lid WHERE lb.bid = :bid AND ll.fail_count > :fail_count AND ll.status = :status AND ll.code NOT IN (:codes)', array(
          ':bid' => arg(5),
          ':fail_count' => 0,
          ':status' => 1,
          ':codes' => $ignore_response_codes,
        ));
        foreach ($links as $link) {
          if (_linkchecker_link_access($link)) {
            drupal_set_message(format_plural($link->fail_count, 'Link check of <a href="@url">@url</a> failed once (status code: @code).', 'Link check of <a href="@url">@url</a> failed @count times (status code: @code).', array(
              '@url' => $link->url,
              '@code' => $link->code,
            )), 'warning', FALSE);
          }
        }
      }

      // Add custom submit handler to custom block configuration form.
      $form['#submit'][] = 'linkchecker_block_custom_configure_form_submit';
      break;
    case 'block_custom_block_delete':

      // Add custom submit handler to custom block delete form.
      $form['#submit'][] = 'linkchecker_block_custom_delete_form_submit';
      break;
  }
}