You are here

function ccl_admin in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl.admin.inc \ccl_admin()

CCL adminitsration form.

1 string reference to 'ccl_admin'
ccl_menu in ./ccl.module
Implements hook_menu().

File

./ccl.admin.inc, line 10
Provides administrative functions for ccl.

Code

function ccl_admin() {
  $result = db_query("SELECT * FROM {ccl}");
  if ($result
    ->rowCount()) {

    // Get content type names.
    $cts = node_type_get_names();

    // Prepare table header.
    $header = array(
      t('Title'),
      t('URL'),
      t('Type'),
      t('Options'),
      t('Operation'),
    );
    $rows = array();
    foreach ($result as $record) {
      $options = array(
        'desc' => '',
        'op' => '',
      );

      // Prepeare the options display.
      if ($record->type == 'node') {
        $link_options = unserialize($record->options);
        switch ($link_options['node_options']) {
          case 'global':
            $options['desc'] = t('Attached to all nodes.');
            break;
          case 'ct':
            $options['desc'] = t('Attached to all nodes of the content type %ct.', array(
              '%ct' => $cts[$link_options['node_type']],
            ));
            break;
          case 'node':
            $node_title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(
              ':nid' => $link_options['node_id'],
            ))
              ->fetchField();
            $options['desc'] = t('Attached to %node_title [NID: !nid].', array(
              '%node_title' => $node_title,
              '!nid' => $link_options['node_id'],
            ));
            break;
        }
        $options['op'] = l(t('Edit'), 'admin/config/user-interface/ccl/' . $record->clid . '/edit') . ' | ' . l(t('Delete'), 'admin/config/user-interface/ccl/' . $record->clid . '/delete');
      }
      else {
        foreach (module_implements('ccl_link_info') as $module) {
          $options = module_invoke($module, 'ccl_link_info', $record);
          if (!empty($options)) {
            break;
          }
        }
      }

      // Prepare table row.
      $rows[] = array(
        $record->title . ' <small>[ID: ' . $record->clid . ']</small>',
        $record->link,
        $record->type,
        $options['desc'],
        $options['op'],
      );
    }
    return theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
  }
  else {
    return array(
      'empty_text' => array(
        '#type' => 'markup',
        '#markup' => '<p>' . t('No custom contextual links have been added yet. <a href="@add-page">Add a link here</a>.', array(
          '@add-page' => url('admin/config/user-interface/ccl/add'),
        )) . '</p>',
      ),
    );
  }
}