Commit bf81bb78 authored by Fran Garcia-Linares's avatar Fran Garcia-Linares Committed by Neil Drumm
Browse files

Issue #1857390 by fjgarlin, slv_, drumm, dww: User can add issues to projects...

Issue #1857390 by fjgarlin, slv_, drumm, dww: User can add issues to projects that doesn't have issue tracking enabled
parent 78d46418
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -60,9 +60,15 @@ function project_issue_pick_project_form($form, &$form_state, $node_type) {
  $form_state['node_type'] = $node_type;

  if (variable_get('project_selection_widget', 'select') == 'select') {
    // Fetch a list of all projects.
    $machine_names = array();
    $projects = project_projects_select_options($machine_names);
    // Fetch a list of all projects with issue tracking enabled.
    $conditions = array(
      array(
        'field' => 'field_project_has_issue_queue',
        'column' => 'value',
        'value' => 1,
      ),
    );
    $projects = project_projects_select_options($conditions);
    if (empty($projects)) {
      drupal_set_message(t('You do not have access to any projects.'), 'error');
    }
+35 −2
Original line number Diff line number Diff line
@@ -366,6 +366,26 @@ function project_issue_node_presave(stdClass $node) {
  }
}

/**
 * Checks whether a project has issue tracker enabled.
 *
 * @param int|object $project
 *   Nid of the project or project object.
 *
 * @return bool|null
 *   True or false if the nid given is a project, null otherwise.
 */
function _project_is_issue_tracker_enabled($project) {
  $project = is_numeric($project) ? node_load($project) : $project;
  if (project_node_is_project($project)) {
    return !empty($project->field_project_has_issue_queue) ?
    (bool) $project->field_project_has_issue_queue[LANGUAGE_NONE][0]['value'] :
    FALSE;
  }

  return NULL;
}

/**
 * Implements hook_form_BASE_FORM_ID_alter() for node_form().
 *
@@ -418,6 +438,10 @@ function project_issue_form_node_form_alter(&$form, &$form_state, $form_id) {

  if (!empty($form_state['node']->field_project[LANGUAGE_NONE][0]['target_id'])) {
    $project = node_load($form_state['node']->field_project[LANGUAGE_NONE][0]['target_id']);
    if (_project_is_issue_tracker_enabled($project) === FALSE) {
      drupal_set_message(t('Issues are not enabled for this project. You will not be able to submit this form.'), 'error');
    }

    project_issue_set_breadcrumb($form_state['node'], $project);
    // Include the project_specific new issue help text on the create form.
    if (empty($form['#node']->nid)) {
@@ -480,7 +504,11 @@ function project_issue_field_project_components_validate($element, &$form_state)
function project_issue_field_project_validate($element, &$form_state) {
  // Always update the node entity saved in form_state in order to allow other
  // fields to be populated with correct values (e.g. 'field_issue_assigned').
  $form_state['node']->field_project[LANGUAGE_NONE][0]['target_id'] = $form_state['values']['field_project'][LANGUAGE_NONE][0]['target_id'];
  $project_nid = $form_state['values']['field_project'][LANGUAGE_NONE][0]['target_id'];
  $form_state['node']->field_project[LANGUAGE_NONE][0]['target_id'] = $project_nid;
  if (_project_is_issue_tracker_enabled($project_nid) === FALSE) {
    form_set_error('field_project', t('Issues are not enabled for this project.'));
  }
}

/**
@@ -1465,7 +1493,12 @@ function project_issue_query_result_links($project_arg = NULL) {
    $project = project_load($project_arg);
    $machine_name = $project->field_project_machine_name[LANGUAGE_NONE][0]['value'];

    if (_project_is_issue_tracker_enabled($project)) {
      $links['create'] = project_issue_get_create_link($project);
    }
    else {
      drupal_set_message(t('Issues are not enabled for this project.'), 'error');
    }
    if (!$is_adv_search) {
      $links['search'] = [
        'title' => t('Advanced search'),
+4 −1
Original line number Diff line number Diff line
@@ -15,7 +15,10 @@ class project_issue_handler_area_issue_create_child extends views_handler_area {
    // argument.
    $parent_nid = $this->view->argument['nid']->get_value();

    if ($parent_project = node_load(node_load($parent_nid)->field_project[LANGUAGE_NONE][0]['target_id'])) {
    if (
      ($parent_project = node_load(node_load($parent_nid)->field_project[LANGUAGE_NONE][0]['target_id'])) &&
      (_project_is_issue_tracker_enabled($parent_project))
    ) {
      return l(
        t('Add child issue'),
        'node/add/project-issue/' . $parent_project->field_project_machine_name[LANGUAGE_NONE][0]['value'],