You are here

function _neutral_paths_admin_form_part in Neutral paths 7

Returns a form part for a particular entity type.

1 call to _neutral_paths_admin_form_part()
neutral_paths_admin in ./neutral_paths.module
Admin form.

File

./neutral_paths.module, line 69
Neutral paths.

Code

function _neutral_paths_admin_form_part($type, $caption) {
  $form = array();
  $num_aliases = db_select('url_alias')
    ->condition('source', $type . '/%', 'LIKE')
    ->countQuery()
    ->execute()
    ->fetchCol();
  $num_aliases = $num_aliases[0];
  $num_neutral_aliases = db_select('url_alias')
    ->condition('language', LANGUAGE_NONE)
    ->condition('source', $type . '/%', 'LIKE')
    ->countQuery()
    ->execute()
    ->fetchCol();
  $num_neutral_aliases = $num_neutral_aliases[0];
  $form['alias_statistics_' . $type] = array(
    '#type' => 'markup',
    '#markup' => '<p>' . $caption . ': ' . $num_neutral_aliases . ' / ' . $num_aliases . '</p>',
  );

  // Path alias of any entity type can be made language neutral.
  $form['np_bulk_neutral_reset' . $type] = array(
    '#type' => 'submit',
    '#value' => t('Reset to neutral'),
    '#name' => 'submit_reset' . $type,
    '#attributes' => $num_aliases == $num_neutral_aliases ? array(
      'disabled' => 'disabled',
    ) : array(),
    '#submit' => array(
      'neutral_paths_admin_submit_reset_' . $type,
    ),
  );

  // FIXME:
  // for now only node-related aliases can be switched to a certain language.
  if ($type == 'node') {
    $form['np_bulk_neutral_localize_' . $type] = array(
      '#type' => 'submit',
      '#value' => t('Reset to localized'),
      '#name' => 'submit_localize_node',
      '#attributes' => $num_neutral_aliases == 0 ? array(
        'disabled' => 'disabled',
      ) : array(),
      '#submit' => array(
        'neutral_paths_admin_submit_localize_nodes',
      ),
    );
  }
  return $form;
}