Having column name next to project tag in hover view

Hello and hope you’re staying safe and healthy.

Could anyone provide pointers on how to tweak Phabricator so as to show column name in parentheses next to project tag when hovering over task — exactly the same way one sees it when viewing a task (in the curtain view)?

I feel it needs somehow the same code as in https://github.com/phacility/phabricator/blob/master/src/applications/project/engineextension/PhabricatorProjectsCurtainExtension.php — but applied in
ProjectBoardTaskCard.php

However I experienced problems applying the engine code and not sure what the best and most efficient way to do it anyway…

Does anybody has ideas?

Thanks!

Re usecase: sometimes, during planning sessions, it is useful to see those details while browsing task tree, without clicking on the task itself.

Sorry, my question was a bit premature, I got it working. My version of ProjectBoardTaskCard.php:

<?php

final class ProjectBoardTaskCard extends Phobject {

  private $viewer;
  private $projectHandles;
  private $task;
  private $owner;
  private $showEditControls;
  private $canEdit;
  private $coverImageFile;
  private $hideArchivedProjects;

  public function setViewer(PhabricatorUser $viewer) {
    $this->viewer = $viewer;
    return $this;
  }
  public function getViewer() {
    return $this->viewer;
  }

  public function setProjectHandles(array $handles) {
    $this->projectHandles = $handles;
    return $this;
  }

  public function getProjectHandles() {
    return $this->projectHandles;
  }

  public function setCoverImageFile(PhabricatorFile $cover_image_file) {
    $this->coverImageFile = $cover_image_file;
    return $this;
  }

  public function getCoverImageFile() {
    return $this->coverImageFile;
  }

  public function setHideArchivedProjects($hide_archived_projects) {
    $this->hideArchivedProjects = $hide_archived_projects;
    return $this;
  }

  public function getHideArchivedProjects() {
    return $this->hideArchivedProjects;
  }

  public function setTask(ManiphestTask $task) {
    $this->task = $task;
    return $this;
  }
  public function getTask() {
    return $this->task;
  }

  public function setOwner(PhabricatorObjectHandle $owner = null) {
    $this->owner = $owner;
    return $this;
  }
  public function getOwner() {
    return $this->owner;
  }

  public function setCanEdit($can_edit) {
    $this->canEdit = $can_edit;
    return $this;
  }

  public function getCanEdit() {
    return $this->canEdit;
  }

  public function setShowEditControls($show_edit_controls) {
    $this->showEditControls = $show_edit_controls;
    return $this;
  }

  public function getShowEditControls() {
    return $this->showEditControls;
  }

  public function getItem() {
    $task = $this->getTask();
    $owner = $this->getOwner();
    $can_edit = $this->getCanEdit();
    $viewer = $this->getViewer();

    $color_map = ManiphestTaskPriority::getColorMap();
    $bar_color = idx($color_map, $task->getPriority(), 'grey');

    $card = id(new PHUIObjectItemView())
      ->setObject($task)
      ->setUser($viewer)
      ->setObjectName($task->getMonogram())
      ->setHeader($task->getTitle())
      ->setHref($task->getURI())
      ->addSigil('project-card')
      ->setDisabled($task->isClosed())
      ->setBarColor($bar_color);

    if ($this->getShowEditControls()) {
      if ($can_edit) {
        $card
          ->addSigil('draggable-card')
          ->addClass('draggable-card');
        $edit_icon = 'fa-pencil';
      } else {
        $card
          ->addClass('not-editable')
          ->addClass('undraggable-card');
        $edit_icon = 'fa-lock red';
      }

      $card->addAction(
        id(new PHUIListItemView())
          ->setName(pht('Edit'))
          ->setIcon($edit_icon)
          ->addSigil('edit-project-card')
          ->setHref('/maniphest/task/edit/'.$task->getID().'/'));
    }

    if ($owner) {
      $card->addHandleIcon($owner, $owner->getName());
    }

    $cover_file = $this->getCoverImageFile();
    if ($cover_file) {
      $card->setCoverImage($cover_file->getBestURI());
    }

    if (ManiphestTaskPoints::getIsEnabled()) {
      $points = $task->getPoints();
      if ($points !== null) {
        $points_tag = id(new PHUITagView())
          ->setType(PHUITagView::TYPE_SHADE)
          ->setColor(PHUITagView::COLOR_GREY)
          ->setSlimShady(true)
          ->setName($points)
          ->addClass('phui-workcard-points');
        $card->addAttribute($points_tag);
      }
    }

    $subtype = $task->newSubtypeObject();
    if ($subtype && $subtype->hasTagView()) {
      $subtype_tag = $subtype->newTagView()
        ->setSlimShady(true);
      $card->addAttribute($subtype_tag);
    }

    if ($task->isClosed()) {
      $icon = ManiphestTaskStatus::getStatusIcon($task->getStatus());
      $icon = id(new PHUIIconView())
        ->setIcon($icon.' grey');
      $card->addAttribute($icon);
      $card->setBarColor('grey');
    }

    $project_handles = $this->getProjectHandles();

    // Remove any archived projects from the list.
    if ($this->hideArchivedProjects) {
      if ($project_handles) {
        foreach ($project_handles as $key => $handle) {
          if ($handle->getStatus() == PhabricatorObjectHandle::STATUS_CLOSED) {
            unset($project_handles[$key]);
          }
        }
      }
    }

    if ($project_handles) {
      // NOTE(aronskiy): added to have annotations available.
      $project_phids = $this->getTask()->getProjectPHIDs();
      $project_phids = array_reverse($project_phids);

      $annotations = array();

      $engine = id(new PhabricatorBoardLayoutEngine())
        ->setViewer($viewer)
        ->setBoardPHIDs($project_phids)
        ->setObjectPHIDs(array($this->getTask()->getPHID()))
        ->executeLayout();

      require_celerity_resource('maniphest-task-summary-css');

      foreach ($project_phids as $project_phid) {

        $columns = $engine->getObjectColumns(
          $project_phid,
          $this->getTask()->getPHID());

        $annotation = array();
        foreach ($columns as $column) {
          $project_id = $column->getProject()->getID();

          $column_name = pht('(%s)', $column->getDisplayName());
          $column_link = phutil_tag(
            'a',
            array(
              'href' => $column->getWorkboardURI(),
              'class' => 'maniphest-board-link',
            ),
            $column_name);

          $annotation[] = $column_link;
        }

        if ($annotation) {
          $annotations[$project_phid] = array(
            ' ',
            phutil_implode_html(', ', $annotation),
          );
        }
      }

      $project_handles = array_reverse($project_handles);
      $tag_list = id(new PHUIHandleTagListView())
        ->setSlim(true)
        ->setHandles($project_handles)
        ->setAnnotations($annotations);
      $card->addAttribute($tag_list);
    }

    $card->addClass('phui-workcard');

    return $card;
  }

}
1 Like