/**
 * Implements hook_block_view_MODULE_DELTA_alter().
 */
function bootstrap_subtheme_block_view_api_navigation_alter(&$data, $block)
{
    $branch = api_get_active_branch();
    if (user_access('access API reference') && !empty($branch)) {
        // Figure out if this is the default branch for this project, the same
        // way the menu system decides.
        $branches = api_get_branches();
        $projects = _api_make_menu_projects();
        $is_default = $branch->branch_name === $projects[$branch->project]['use branch'];
        $suffix = $is_default ? '' : '/' . $branch->branch_name;
        $types = array('groups' => t('Topics'), 'classes' => t('Classes'), 'functions' => t('Functions'), 'files' => t('Files'), 'namespaces' => t('Namespaces'), 'services' => t('Services'), 'constants' => t('Constants'), 'globals' => t('Globals'), 'deprecated' => t('Deprecated'));
        $links = array('#theme_wrappers' => array('container__api__navigation'), '#attributes' => array('class' => array('list-group')));
        $current_path = current_path();
        $counts = api_listing_counts($branch);
        $item = _db_api_active_item();
        foreach ($types as $type => $title) {
            if ($type === '' || $counts[$type] > 0) {
                $branch_path = 'api/' . $branch->project;
                $path = $branch_path;
                if ($type) {
                    $path .= "/{$type}";
                    $title = '<span class="badge">' . $counts[$type] . '</span>' . $title;
                }
                $path .= $suffix;
                $class = array('list-group-item');
                if ($type || $type === '' && !$counts['groups']) {
                    if ($type === 'groups') {
                        $path = $branch_path . $suffix;
                    }
                    if ($path === $current_path || $item && preg_match('/^' . $item->object_type . '/', $type)) {
                        $class[] = 'active';
                    }
                    $links[] = array('#theme' => 'link__api__navigation_link', '#text' => $title, '#path' => $path, '#options' => array('html' => TRUE, 'attributes' => array('class' => $class)));
                } else {
                    $links[] = array('#theme' => 'html_tag__api__navigation_link', '#tag' => 'div', '#value' => $title, '#attributes' => array('class' => $class));
                }
            }
        }
        $items = array();
        foreach ($branches as $obj) {
            $is_default = $obj->branch_name === $projects[$obj->project]['use branch'];
            $suffix = $is_default ? '' : '/' . $obj->branch_name;
            $items[] = array('#theme' => 'link', '#text' => $obj->title, '#path' => 'api/' . $obj->project . $suffix, '#options' => array('html' => FALSE, 'attributes' => array()), '#active' => $branch->branch_name === $obj->branch_name);
        }
        $data = array('subject' => t('API Navigation'), 'content' => array('links' => $links, 'branches' => array('#theme' => 'bootstrap_dropdown', '#toggle' => array('#theme' => 'button', '#button_type' => 'button', '#value' => t('Projects') . ' <span class="caret"></span>', '#attributes' => array('class' => array('btn-default', 'btn-block'))), '#items' => $items)));
    }
}
Esempio n. 2
0
 /**
  * Sets up a files branch using the user interface.
  *
  * @param $prefix
  *   Directory prefix to prepend on the data directories.
  * @param $default
  *   TRUE to set this as the default branch; FALSE to not set it as default.
  * @param $info
  *   Array of branch information to override the defaults (see function
  *   code to see what they are). Note that $prefix is applied after this
  *   information is read, and that only one directory and one excluded are
  *   supported in this function. You can set $info['excluded'] to 'none' to
  *   completely omit the excluded directories setting.
  *
  * @return
  *   Array of information (defaults with overrides) used to create the
  *   branch.
  */
 function setUpBranchUI($prefix = '', $default = TRUE, $info = array())
 {
     // Set up defaults.
     $info += array('project' => 'test', 'project_title' => 'Project 6', 'branch_name' => '6', 'title' => 'Testing 6', 'directory' => drupal_get_path('module', 'api') . '/tests/sample', 'excluded' => drupal_get_path('module', 'api') . '/tests/sample/to_exclude');
     $info['data[directories]'] = $prefix . $info['directory'];
     if ($info['excluded'] != 'none') {
         $info['data[excluded_directories]'] = $prefix . $info['excluded'];
     }
     unset($info['directory']);
     unset($info['excluded']);
     $this->drupalPost('admin/settings/api/branches/new/files', $info, t('Save branch'));
     if ($default) {
         // Make this the default branch.
         $branches = api_get_branches(TRUE);
         $this_id = 0;
         foreach ($branches as $branch) {
             if ($branch->title == $info['title']) {
                 $this_id = $branch->branch_id;
                 break;
             }
         }
         $this->drupalPost('admin/settings/api/branches/list', array('default_branch' => $this_id), t('Save changes'));
     }
     return $info;
 }
Esempio n. 3
0
 /**
  * Sets up a project and branch using the user interface.
  *
  * @param $prefix
  *   Directory prefix to prepend on the data directories.
  * @param $default
  *   TRUE to set this as the default branch; FALSE to not set it as default.
  * @param $info
  *   Array of information to override the defaults (see function code to see
  *   what they are). Note that $prefix is applied after this information is
  *   read, and that only one directory and one excluded are supported in this
  *   function.
  *
  * @return
  *   Array of information (defaults with overrides) used to create the
  *   branch and project.
  */
 function setUpBranchUI($prefix = '', $default = TRUE, $info = array())
 {
     // Set up defaults.
     $info += array('project' => 'test', 'project_title' => 'Project 6', 'project_type' => 'module', 'branch_name' => '6', 'title' => 'Testing 6', 'core_compatibility' => '7.x', 'update_frequency' => 1, 'directory' => drupal_get_path('module', 'api') . '/tests/sample', 'excluded' => drupal_get_path('module', 'api') . '/tests/sample/to_exclude', 'exclude_drupalism_regexp' => '', 'regexps' => '');
     $info['preferred'] = $default ? 1 : 0;
     // Create the project.
     $project_info = array('project_name' => $info['project'], 'project_type' => $info['project_type'], 'project_title' => $info['project_title']);
     $this->drupalPost('admin/config/development/api/projects/new', $project_info, t('Save project'));
     // Create the branch.
     $branch_info = array('project' => $info['project'], 'branch_name' => $info['branch_name'], 'title' => $info['title'], 'preferred' => $info['preferred'], 'core_compatibility' => $info['core_compatibility'], 'update_frequency' => $info['update_frequency'], 'data[directories]' => $prefix . $info['directory'], 'data[exclude_files_regexp]' => $info['regexps'], 'data[exclude_drupalism_regexp]' => $info['exclude_drupalism_regexp']);
     if ($info['excluded'] != 'none') {
         $branch_info['data[excluded_directories]'] = $prefix . $info['excluded'];
     }
     $this->drupalPost('admin/config/development/api/branches/new', $branch_info, t('Save branch'));
     if ($default) {
         // Make this the default project/core compat. This has to be done after
         // the setup for the branch, because the API module will override the
         // setting if the branch doesn't exist yet, in an attempt to make sure
         // a branch exists.
         $this->drupalPost('admin/config/development/api', array('api_default_core_compatibility' => $info['core_compatibility'], 'api_default_project' => $info['project']), t('Save configuration'));
         $branches = api_get_branches(TRUE);
         $this_id = 0;
         foreach ($branches as $branch) {
             if ($branch->title == $info['title']) {
                 $this->assertEqual(variable_get('api_default_branch', 99), $branch->branch_id, 'Variable for default branch is set correctly');
                 break;
             }
         }
     }
     return $info;
 }