Page MenuHomePhabricator
Paste P1094

ExampleCustomField.php
ActivePublic

Authored by epriestley on Mar 18 2014, 2:18 AM.
Tags
None
Subscribers
Tokens
"Like" token, awarded by ofbeaton.
<?php
final class ExampleCustomField extends ManiphestCustomField {
public function getFieldKey() {
return 'example:test';
}
public function shouldAppearInPropertyView() {
return true;
}
public function renderPropertyViewLabel() {
return pht('Dependency Graph');
}
public function renderPropertyViewValue(array $handles) {
$task = $this->getObject();
$edge_type = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
$graph = id(new PhabricatorEdgeGraph())
->setEdgeType($edge_type)
->addNodes(
array(
'<seed>' => array($task->getPHID()),
))
->loadGraph();
$nodes = $graph->getNodes();
unset($nodes['<seed>']);
if (count($nodes) == 1) {
return null;
}
$phids = array_keys($nodes);
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->getViewer())
->withPHIDs($phids)
->execute();
return $this->drawNodes($task->getPHID(), $nodes, $handles, true);
}
private function drawNodes($phid, $nodes, $handles, $is_top = false) {
$content = array();
if (!$is_top) {
$content[] = phutil_tag('li', array(), $handles[$phid]->renderLink());
}
foreach ($nodes[$phid] as $other) {
$content[] = phutil_tag(
'li',
array(
'style' => $is_top ? null : 'padding-left: 16px;',
),
$this->drawNodes($other, $nodes, $handles));
}
return phutil_tag('ul', array(), $content);
}
}

Event Timeline

epriestley edited the content of this paste. (Show Details)Mar 18 2014, 2:18 AM
epriestley changed the title of this paste from untitled to ExampleCustomField.php.
epriestley updated the paste's language from autodetect to autodetect.
fanis added a subscriber: fanis.Aug 26 2015, 12:53 PM

$edge_type = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
This won't work in current code, since December 2014

Use ManiphestTaskDependsOnTaskEdgeType::EDGECONST instead

Hi guys, any update on this general issue of viewing subtasks in a nested manner?

I tried the above code for ExampleCustomField in the current (master) version of Phabricator. Neither of the 2 options work for $edge_type

PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
or
ManiphestTaskDependsOnTaskEdgeType::EDGECONST;

chad added a subscriber: chad.Jan 22 2016, 2:46 AM

Hi guys, any update on this general issue of viewing subtasks in a nested manner?

Every task here is 100% up to date, we don't have a secret second install with "real" updates. Just go to T4207 and click subscribe!

You may also want to follow T10034.

ofbeaton added a subscriber: ofbeaton.
OCram added a subscriber: OCram.Jun 14 2016, 9:06 AM

Does this workaround change anything in the database? - I'm thinking about using this in our production environment ;)

@OCram I've been using it in production for months, it works well enough for our needs, including in the current codebase. It just displays child tasks in a tree-like manner, doesn't change anything.