@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow EditEngine to build NUX buttons that point at the right place

Summary:
Fixes T11812.

- Pull the logic for building the "Create Whatever" dropdown out.
- Use it to generate NUX buttons, too.
- Use the new logic in Paste and Maniphest.

Test Plan:
- Viewed Paste NUX, button worked.
- Viewed Maniphest NUX with multiple create forms, button worked.

Reviewers: chad, avivey

Reviewed By: avivey

Subscribers: avivey

Maniphest Tasks: T11812

Differential Revision: https://secure.phabricator.com/D16797

+103 -54
+5 -5
src/applications/maniphest/query/ManiphestTaskSearchEngine.php
··· 405 405 } 406 406 407 407 protected function getNewUserBody() { 408 - $create_button = id(new PHUIButtonView()) 409 - ->setTag('a') 410 - ->setText(pht('Create a Task')) 411 - ->setHref('/maniphest/task/edit/') 412 - ->setColor(PHUIButtonView::GREEN); 408 + $viewer = $this->requireViewer(); 409 + 410 + $create_button = id(new ManiphestEditEngine()) 411 + ->setViewer($viewer) 412 + ->newNUXBUtton(pht('Create a Task')); 413 413 414 414 $icon = $this->getApplication()->getIcon(); 415 415 $app_name = $this->getApplication()->getName();
+5 -5
src/applications/paste/query/PhabricatorPasteSearchEngine.php
··· 204 204 } 205 205 206 206 protected function getNewUserBody() { 207 - $create_button = id(new PHUIButtonView()) 208 - ->setTag('a') 209 - ->setText(pht('Create a Paste')) 210 - ->setHref('/paste/create/') 211 - ->setColor(PHUIButtonView::GREEN); 207 + $viewer = $this->requireViewer(); 208 + 209 + $create_button = id(new PhabricatorPasteEditEngine()) 210 + ->setViewer($viewer) 211 + ->newNUXButton(pht('Create a Paste')); 212 212 213 213 $icon = $this->getApplication()->getIcon(); 214 214 $app_name = $this->getApplication()->getName();
+93 -44
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 1352 1352 } 1353 1353 1354 1354 1355 + public function newNUXButton($text) { 1356 + $specs = $this->newCreateActionSpecifications(array()); 1357 + $head = head($specs); 1358 + 1359 + return id(new PHUIButtonView()) 1360 + ->setTag('a') 1361 + ->setText($text) 1362 + ->setHref($head['uri']) 1363 + ->setDisabled($head['disabled']) 1364 + ->setWorkflow($head['workflow']) 1365 + ->setColor(PHUIButtonView::GREEN); 1366 + } 1367 + 1368 + 1355 1369 final public function addActionToCrumbs( 1356 1370 PHUICrumbsView $crumbs, 1357 1371 array $parameters = array()) { 1372 + $viewer = $this->getViewer(); 1373 + 1374 + $specs = $this->newCreateActionSpecifications($parameters); 1375 + 1376 + $head = head($specs); 1377 + $menu_uri = $head['uri']; 1378 + 1379 + $dropdown = null; 1380 + if (count($specs) > 1) { 1381 + $menu_icon = 'fa-caret-square-o-down'; 1382 + $menu_name = $this->getObjectCreateShortText(); 1383 + $workflow = false; 1384 + $disabled = false; 1385 + 1386 + $dropdown = id(new PhabricatorActionListView()) 1387 + ->setUser($viewer); 1388 + 1389 + foreach ($specs as $spec) { 1390 + $dropdown->addAction( 1391 + id(new PhabricatorActionView()) 1392 + ->setName($spec['name']) 1393 + ->setIcon($spec['icon']) 1394 + ->setHref($spec['uri'])) 1395 + ->setDisabled($head['disabled']) 1396 + ->setWorkflow($head['workflow']); 1397 + } 1398 + 1399 + } else { 1400 + $menu_icon = $head['icon']; 1401 + $menu_name = $head['name']; 1402 + 1403 + $workflow = $head['workflow']; 1404 + $disabled = $head['disabled']; 1405 + } 1406 + 1407 + $action = id(new PHUIListItemView()) 1408 + ->setName($menu_name) 1409 + ->setHref($menu_uri) 1410 + ->setIcon($menu_icon) 1411 + ->setWorkflow($workflow) 1412 + ->setDisabled($disabled); 1413 + 1414 + if ($dropdown) { 1415 + $action->setDropdownMenu($dropdown); 1416 + } 1417 + 1418 + $crumbs->addAction($action); 1419 + } 1420 + 1421 + 1422 + /** 1423 + * Build a raw description of available "Create New Object" UI options so 1424 + * other methods can build menus or buttons. 1425 + */ 1426 + private function newCreateActionSpecifications(array $parameters) { 1358 1427 $viewer = $this->getViewer(); 1359 1428 1360 1429 $can_create = $this->hasCreateCapability(); ··· 1364 1433 $configs = array(); 1365 1434 } 1366 1435 1367 - $dropdown = null; 1368 1436 $disabled = false; 1369 1437 $workflow = false; 1370 1438 1371 1439 $menu_icon = 'fa-plus-square'; 1372 - 1440 + $specs = array(); 1373 1441 if (!$configs) { 1374 1442 if ($viewer->isLoggedIn()) { 1375 1443 $disabled = true; ··· 1385 1453 } else { 1386 1454 $create_uri = $this->getEditURI(null, 'nocreate/'); 1387 1455 } 1388 - } else { 1389 - $config = head($configs); 1390 - $form_key = $config->getIdentifier(); 1391 - $create_uri = $this->getEditURI(null, "form/{$form_key}/"); 1392 1456 1393 - if ($parameters) { 1394 - $create_uri = (string)id(new PhutilURI($create_uri)) 1395 - ->setQueryParams($parameters); 1396 - } 1397 - 1398 - if (count($configs) > 1) { 1399 - $menu_icon = 'fa-caret-square-o-down'; 1400 - 1401 - $dropdown = id(new PhabricatorActionListView()) 1402 - ->setUser($viewer); 1403 - 1404 - foreach ($configs as $config) { 1405 - $form_key = $config->getIdentifier(); 1406 - $config_uri = $this->getEditURI(null, "form/{$form_key}/"); 1407 - 1408 - if ($parameters) { 1409 - $config_uri = (string)id(new PhutilURI($config_uri)) 1410 - ->setQueryParams($parameters); 1411 - } 1412 - 1413 - $item_icon = 'fa-plus'; 1457 + $specs[] = array( 1458 + 'name' => $this->getObjectCreateShortText(), 1459 + 'uri' => $create_uri, 1460 + 'icon' => $menu_icon, 1461 + 'disabled' => $disabled, 1462 + 'workflow' => $workflow, 1463 + ); 1464 + } else { 1465 + foreach ($configs as $config) { 1466 + $form_key = $config->getIdentifier(); 1467 + $config_uri = $this->getEditURI(null, "form/{$form_key}/"); 1414 1468 1415 - $dropdown->addAction( 1416 - id(new PhabricatorActionView()) 1417 - ->setName($config->getDisplayName()) 1418 - ->setIcon($item_icon) 1419 - ->setHref($config_uri)); 1469 + if ($parameters) { 1470 + $config_uri = (string)id(new PhutilURI($config_uri)) 1471 + ->setQueryParams($parameters); 1420 1472 } 1421 - } 1422 - } 1423 1473 1424 - $action = id(new PHUIListItemView()) 1425 - ->setName($this->getObjectCreateShortText()) 1426 - ->setHref($create_uri) 1427 - ->setIcon($menu_icon) 1428 - ->setWorkflow($workflow) 1429 - ->setDisabled($disabled); 1430 - 1431 - if ($dropdown) { 1432 - $action->setDropdownMenu($dropdown); 1474 + $specs[] = array( 1475 + 'name' => $config->getDisplayName(), 1476 + 'uri' => $config_uri, 1477 + 'icon' => 'fa-plus', 1478 + 'disabled' => false, 1479 + 'workflow' => false, 1480 + ); 1481 + } 1433 1482 } 1434 1483 1435 - $crumbs->addAction($action); 1484 + return $specs; 1436 1485 } 1437 1486 1438 1487 final public function buildEditEngineCommentView($object) {