You are here

function audit_log_filter_by_entity_form in Audit Log 7

Render admin form to select entity types and bundles.

audit_log_exclude_entity_types

  • Entity1

-- Bundle 1 --- View --- Insert --- Update --- Delete -- Bundle 2 --- View --- Insert --- Update --- Delete

  • Entity2

-- Bundle 1 --- View --- Insert --- Update --- Delete

1 string reference to 'audit_log_filter_by_entity_form'
audit_log_filter_menu in modules/audit_log_filter/audit_log_filter.module
Implements hook_menu().

File

modules/audit_log_filter/audit_log_filter.admin.inc, line 44
Hook implemenations for the Audit database logging module.

Code

function audit_log_filter_by_entity_form($form, &$form_state) {
  $entity_info = entity_get_info();
  $actions = audit_log_action_options();
  $form['description'] = array(
    '#markup' => t('Select the Entity Type, Bundle, and/or action you would like to exclude from being logged below.'),
  );
  $form['audit_log_exclude_entity_types'] = array(
    '#type' => 'container',
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'audit_log_filter') . '/js/entity_filter.js',
      ),
    ),
  );
  $alf_exclude = variable_get('audit_log_exclude_entity_types', array());
  foreach ($entity_info as $entity_type => $info) {

    // Selecting this will select all bundles and actions.
    $form['audit_log_exclude_entity_types'][$entity_type . '-all'] = array(
      '#type' => 'checkbox',
      '#title' => t($info['label']),
      '#default_value' => isset($alf_exclude[$entity_type . '-all']) ? $alf_exclude[$entity_type . '-all'] : FALSE,
    );

    // This makes the form appear as a "tree" and gives an array structure.
    $form['audit_log_exclude_entity_types'][$entity_type] = array(
      '#type' => 'container',
      '#attributes' => array(
        'style' => 'padding-left:2em;',
      ),
    );
    foreach ($info['bundles'] as $bundle_name => $bundle_info) {

      // Selecting this will select all actions for the bundle.
      $form['audit_log_exclude_entity_types'][$entity_type][$bundle_name . '-all'] = array(
        '#type' => 'checkbox',
        '#title' => t($bundle_info['label']),
        '#default_value' => isset($alf_exclude[$entity_type][$bundle_name . '-all']) ? $alf_exclude[$entity_type][$bundle_name . '-all'] : FALSE,
      );

      // This makes the actions appear to branch out further than the bundles.
      // also like above... makes a pretty array.
      $form['audit_log_exclude_entity_types'][$entity_type][$bundle_name] = array(
        '#type' => 'container',
        '#attributes' => array(
          'style' => 'padding-left:2em;',
        ),
      );
      foreach ($actions as $action_name => $action_label) {
        $form['audit_log_exclude_entity_types'][$entity_type][$bundle_name][$action_name] = array(
          '#type' => 'checkbox',
          '#title' => t($action_label),
          '#default_value' => isset($alf_exclude[$entity_type][$bundle_name][$action_name]) ? $alf_exclude[$entity_type][$bundle_name][$action_name] : FALSE,
        );
      }
    }
  }
  $form['#tree'] = TRUE;
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}