You are here

editoria11y.module in Editoria11y Accessibility Checker 7

Same filename and directory in other branches
  1. 1.0.x editoria11y.module

Editoria11y module file.

File

editoria11y.module
View source
<?php

/**
 * @file
 * Editoria11y module file.
 */

/**
 * Implements hook_permission().
 */
function editoria11y_permission() {
  return array(
    'use editoria11y checker' => array(
      'title' => t('Use Editoria11y Checker'),
    ),
    'administer editoria11y' => array(
      'title' => t('Administer Editoria11y'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function editoria11y_menu() {
  $items = array();
  $items['admin/config/content/editoria11y'] = array(
    'title' => 'Editoria11y',
    'description' => 'Accessibility checker notifications and exclusions.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'editoria11y_form',
    ),
    'access arguments' => array(
      'administer editoria11y',
    ),
  );
  return $items;
}

/**
 * Page callback: editoria11y form.
 *
 * @see editoria11y_menu()
 */
function editoria11y_form($form, &$form_state) {
  $form['setup'] = array(
    '#type' => 'fieldset',
    '#title' => t('Inclusions &amp; exclusions'),
  );
  $form['setup']['editoria11y_content_root'] = [
    '#title' => t("Check content in this container"),
    '#type' => 'textfield',
    '#placeholder' => 'body',
    '#description' => t('If all editorial content is in <strong>one</strong> element (e.g., <code>main</code> or <code>#content</code>), provide that single <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors">selector</a>.'),
    '#default_value' => variable_get('editoria11y_content_root'),
  ];
  $form['setup']['editoria11y_ignore_containers'] = [
    '#title' => t("Skip over these elements"),
    '#type' => 'textarea',
    '#placeholder' => '#toolbar-administration, .contextual-region > nav, .search-results',
    '#description' => t('Provide a comma-separated list of selectors for elements to ignore, such as <code>.my-embedded-social-media-feed, #sidebar-menu</code>.'),
    '#default_value' => variable_get('editoria11y_ignore_containers'),
  ];
  $form['setup']['editoria11y_no_load'] = [
    '#title' => t("Disable the scanner if these elements are detected"),
    '#type' => 'textarea',
    '#placeholder' => '#overlay-container, .panels-ipe-editing, #quickedit-entity-toolbar',
    '#description' => t('Provided a comma-separated list of selectors unique to pages or states that should not be scanned; e.g, during inline editing  (<code>#inline-editor-open</code>) or on pages without user-editable content (<code>.node-261, .front</code>).'),
    '#default_value' => variable_get('editoria11y_no_load'),
  ];
  $form['results'] = array(
    '#type' => 'fieldset',
    '#title' => t('Tests'),
  );
  $form['results']['editoria11y_assertiveness'] = [
    '#title' => t("Open the issue details panel automatically when new issues are detected"),
    '#type' => 'radios',
    '#options' => array(
      'smart' => t('When nodes are created or changed'),
      'assertive' => t('Always'),
      'polite' => t('Never'),
    ),
    '#description' => t('"Always" is not recommended for sites with multiple editors.'),
    '#default_value' => variable_get('editoria11y_assertiveness'),
  ];
  $form['results']['editoria11y_download_links'] = [
    '#title' => t("Warn that these links need manual review"),
    '#type' => 'textarea',
    '#placeholder' => "a[href\$='.pdf'], a[href*='.doc']",
    '#description' => t('Provide a comma-separated list of selectors for links that should have a "this file download needs a manual check" warning, e.g.: <code>[href^="/download"], .a[data-entity-substitution^="media"]</code>.'),
    '#default_value' => variable_get('editoria11y_download_links'),
  ];
  $form['results']['editoria11y_embedded_content_warning'] = [
    '#title' => t("Warn that these elements need manual review"),
    '#type' => 'textarea',
    '#description' => t('Provide a comma-separated list of selectors for elements with potentially complex issues, e.g.: <code>.my-embedded-feed, #my-social-link-block</code>.<br> Note that this test currently only runs during a "full check," and it <strong>ignores the ignore list</strong>: you are specifying that this element has not been checked.'),
    '#default_value' => variable_get('editoria11y_embedded_content_warning'),
  ];
  $form['theme'] = array(
    '#type' => 'fieldset',
    '#title' => t('Theme compatibility'),
  );
  $form['theme']['editoria11y_allow_overflow'] = [
    '#title' => t("Force these containers to allow overflow when tips are open"),
    '#type' => 'textarea',
    '#placeholder' => 'automatic',
    '#description' => t('Page elements themed with overflow:hidden will truncate tooltips that appear inside them. When this field is blank, Editoria11y tries to override this automatically. To manually choose which elements will toggle overflow, provide a comma-separated list of selectors for elements restricting overflow.'),
    '#default_value' => variable_get('editoria11y_allow_overflow'),
  ];
  $form['theme']['editoria11y_hidden_handlers'] = [
    '#title' => t("Theme JS will handle revealing hidden tooltips inside these containers"),
    '#type' => 'textarea',
    '#description' => t('Editoria11y detects hidden tooltips and warns the user when they try to jump to them from the panel. For elements on this list, Editoria11y will <a href="https://itmaybejj.github.io/editoria11y/#dealing-with-alerts-on-hidden-or-size-constrained-content">dispatch a JS event</a> instead of a warning, so custom JS in your theme can first reveal the hidden tip (e.g., open an accordion or tab panel).'),
    '#default_value' => variable_get('editoria11y_hidden_handlers'),
  ];
  $form['text'] = array(
    '#markup' => '<p>Configuration and troubleshooting tips: <ol><li><a href="/admin/people/permissions">Editorial roles</a> need to have the "View Editoria11y" permission.</li><li>If permissions are correct but the toggle still does not appear, selectors in the "disable the scanner if..." field could be present on the page.</li><li>If the toggle appears but errors are never found, make sure the "check content in" is set to the element that contains the content, and "skip over these" <strong><em>is not</em></strong>.</li><li>Note that an invalid configuration will prevent scanning and throw a JavaScript error; <a href="https://developer.mozilla.org/en-US/docs/Tools/Browser_Console">check the browser console</a></li></ol>',
  );
  return system_settings_form($form);
}

/**
 * Implements hook_libraries_info().
 */
function editoria11y_libraries_info() {
  $libraries['editoria11y'] = array(
    'name' => 'editoria11y',
    'files' => array(
      'js' => array(
        'js/editoria11y-prefs.js',
        'js/editoria11y-drupal.js',
      ),
      'css' => array(
        'css/editoria11y.css',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements init()
 *
 * @link https://api.drupal.org/api/drupal/modules%21node%21node.module/function/template_preprocess_node/7.x
 * Only load for authorized users viewing rendered (non-admin) content.
 */
function editoria11y_preprocess_page(&$vars) {

  // Add JS & CSS by node type.
  if (user_access('use editoria11y checker') && !path_is_admin(current_path())) {
    $lastChanged = 0;
    if (isset($vars['node'])) {
      $lastChanged = $vars['node']->changed;
    }

    // Tell Javascript if slide counter is in use, add class for designers.
    $my_settings = array(
      'type' => 'setting',
      'data' => array(
        'assertiveness' => variable_get('editoria11y_assertiveness', 'smart'),
        'changed' => $lastChanged,
        'allow_overflow' => variable_get('editoria11y_allow_overflow', ''),
        'no_load' => variable_get('editoria11y_no_load', ''),
        'content_root' => variable_get('editoria11y_content_root', ''),
        'ignore_containers' => variable_get('editoria11y_ignore_containers', ''),
        'embedded_content_warning' => variable_get('editoria11y_embedded_content_warning', ''),
        'hidden_handlers' => variable_get('editoria11y_hidden_handlers', ''),
        'download_links' => variable_get('editoria11y_download_links', ''),
      ),
    );
    drupal_add_js(array(
      'editoria11y' => $my_settings,
    ), 'setting');
    drupal_add_js(drupal_get_path('module', 'editoria11y') . '/js/editoria11y-prefs.js', array(
      'scope' => 'footer',
    ));
    drupal_add_js(drupal_get_path('module', 'editoria11y') . '/js/editoria11y-localization.js', array(
      'scope' => 'footer',
    ));
    drupal_add_js(drupal_get_path('module', 'editoria11y') . '/js/editoria11y-drupal.js', array(
      'scope' => 'footer',
    ));
    drupal_add_css(drupal_get_path('module', 'editoria11y') . '/css/editoria11y.css', array(
      'scope' => 'footer',
    ));
  }
}

Functions

Namesort descending Description
editoria11y_form Page callback: editoria11y form.
editoria11y_libraries_info Implements hook_libraries_info().
editoria11y_menu Implements hook_menu().
editoria11y_permission Implements hook_permission().
editoria11y_preprocess_page Implements init()