@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.

Choose default project image by icon

Summary: Builds out a map for icon->image in Projects, selects the icon's image as the default project image if there is no custom image chosen by the user.

Test Plan: Select various icons, see image change. Test choose picture, pick a new image.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

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

+68 -41
+16
src/applications/files/builtin/PhabricatorFilesOnDiskBuiltinFile.php
··· 56 56 return $map; 57 57 } 58 58 59 + public function getProjectBuiltinFiles() { 60 + $root = dirname(phutil_get_library_root('phabricator')); 61 + $root = $root.'/resources/builtin/projects/'; 62 + 63 + $map = array(); 64 + $list = id(new FileFinder($root)) 65 + ->withType('f') 66 + ->withFollowSymlinks(true) 67 + ->find(); 68 + 69 + foreach ($list as $file) { 70 + $map[$file] = $root.$file; 71 + } 72 + return $map; 73 + } 74 + 59 75 }
+2
src/applications/project/config/PhabricatorProjectConfigOptions.php
··· 34 34 - `key` //Required string.// Internal key identifying the icon. 35 35 - `name` //Required string.// Human-readable icon name. 36 36 - `icon` //Required string.// Specifies which actual icon image to use. 37 + - `image` //Optional string.// Selects a default image. Select an image from 38 + `resources/builtins/projects/`. 37 39 - `default` //Optional bool.// Selects a default icon. Exactly one icon must 38 40 be selected as the default. 39 41 - `disabled` //Optional bool.// If true, this icon will no longer be
+4 -1
src/applications/project/controller/PhabricatorProjectEditPictureController.php
··· 98 98 $form = id(new PHUIFormLayoutView()) 99 99 ->setUser($viewer); 100 100 101 - $default_image = PhabricatorFile::loadBuiltin($viewer, 'project.png'); 101 + $builtin = PhabricatorProjectIconSet::getIconImage( 102 + $project->getIcon()); 103 + $default_image = PhabricatorFile::loadBuiltin($this->getViewer(), 104 + 'projects/'.$builtin); 102 105 103 106 $images = array(); 104 107
-32
src/applications/project/editor/PhabricatorProjectTransactionEditor.php
··· 296 296 } 297 297 } 298 298 299 - if ($this->getIsNewObject()) { 300 - $this->setDefaultProfilePicture($object); 301 - } 302 - 303 299 // TODO: We should dump an informational transaction onto the parent 304 300 // project to show that we created the sub-thing. 305 301 ··· 456 452 457 453 return $results; 458 454 } 459 - 460 - private function setDefaultProfilePicture(PhabricatorProject $project) { 461 - if ($project->isMilestone()) { 462 - return; 463 - } 464 - 465 - $compose_color = $project->getDisplayIconComposeColor(); 466 - $compose_icon = $project->getDisplayIconComposeIcon(); 467 - 468 - $builtin = id(new PhabricatorFilesComposeIconBuiltinFile()) 469 - ->setColor($compose_color) 470 - ->setIcon($compose_icon); 471 - 472 - $data = $builtin->loadBuiltinFileData(); 473 - 474 - $file = PhabricatorFile::newFromFileData( 475 - $data, 476 - array( 477 - 'name' => $builtin->getBuiltinDisplayName(), 478 - 'profile' => true, 479 - 'canCDN' => true, 480 - )); 481 - 482 - $project 483 - ->setProfileImagePHID($file->getPHID()) 484 - ->save(); 485 - } 486 - 487 455 488 456 protected function shouldApplyHeraldRules( 489 457 PhabricatorLiskDAO $object,
+42
src/applications/project/icon/PhabricatorProjectIconSet.php
··· 18 18 'icon' => 'fa-briefcase', 19 19 'name' => pht('Project'), 20 20 'default' => true, 21 + 'image' => 'v3/briefcase.png', 21 22 ), 22 23 array( 23 24 'key' => 'tag', 24 25 'icon' => 'fa-tags', 25 26 'name' => pht('Tag'), 27 + 'image' => 'v3/tag.png', 26 28 ), 27 29 array( 28 30 'key' => 'policy', 29 31 'icon' => 'fa-lock', 30 32 'name' => pht('Policy'), 33 + 'image' => 'v3/lock.png', 31 34 ), 32 35 array( 33 36 'key' => 'group', 34 37 'icon' => 'fa-users', 35 38 'name' => pht('Group'), 39 + 'image' => 'v3/people.png', 36 40 ), 37 41 array( 38 42 'key' => 'folder', 39 43 'icon' => 'fa-folder', 40 44 'name' => pht('Folder'), 45 + 'image' => 'v3/folder.png', 41 46 ), 42 47 array( 43 48 'key' => 'timeline', 44 49 'icon' => 'fa-calendar', 45 50 'name' => pht('Timeline'), 51 + 'image' => 'v3/calendar.png', 46 52 ), 47 53 array( 48 54 'key' => 'goal', 49 55 'icon' => 'fa-flag-checkered', 50 56 'name' => pht('Goal'), 57 + 'image' => 'v3/flag.png', 51 58 ), 52 59 array( 53 60 'key' => 'release', 54 61 'icon' => 'fa-truck', 55 62 'name' => pht('Release'), 63 + 'image' => 'v3/truck.png', 56 64 ), 57 65 array( 58 66 'key' => 'bugs', 59 67 'icon' => 'fa-bug', 60 68 'name' => pht('Bugs'), 69 + 'image' => 'v3/bug.png', 61 70 ), 62 71 array( 63 72 'key' => 'cleanup', 64 73 'icon' => 'fa-trash-o', 65 74 'name' => pht('Cleanup'), 75 + 'image' => 'v3/trash.png', 66 76 ), 67 77 array( 68 78 'key' => 'umbrella', 69 79 'icon' => 'fa-umbrella', 70 80 'name' => pht('Umbrella'), 81 + 'image' => 'v3/umbrella.png', 71 82 ), 72 83 array( 73 84 'key' => 'communication', 74 85 'icon' => 'fa-envelope', 75 86 'name' => pht('Communication'), 87 + 'image' => 'v3/mail.png', 76 88 ), 77 89 array( 78 90 'key' => 'organization', 79 91 'icon' => 'fa-building', 80 92 'name' => pht('Organization'), 93 + 'image' => 'v3/organization.png', 81 94 ), 82 95 array( 83 96 'key' => 'infrastructure', 84 97 'icon' => 'fa-cloud', 85 98 'name' => pht('Infrastructure'), 99 + 'image' => 'v3/cloud.png', 86 100 ), 87 101 array( 88 102 'key' => 'account', 89 103 'icon' => 'fa-credit-card', 90 104 'name' => pht('Account'), 105 + 'image' => 'v3/creditcard.png', 91 106 ), 92 107 array( 93 108 'key' => 'experimental', 94 109 'icon' => 'fa-flask', 95 110 'name' => pht('Experimental'), 111 + 'image' => 'v3/experimental.png', 96 112 ), 97 113 array( 98 114 'key' => 'milestone', 99 115 'icon' => 'fa-map-marker', 100 116 'name' => pht('Milestone'), 101 117 'special' => self::SPECIAL_MILESTONE, 118 + 'image' => 'v3/marker.png', 102 119 ), 103 120 ); 104 121 } ··· 149 166 return idx($spec, 'name', null); 150 167 } 151 168 169 + public static function getIconImage($key) { 170 + $spec = self::getIconSpec($key); 171 + return idx($spec, 'image', 'v3/briefcase.png'); 172 + } 173 + 152 174 private static function getIconSpec($key) { 153 175 $icons = self::getIconSpecifications(); 154 176 foreach ($icons as $icon) { ··· 190 212 'key' => 'string', 191 213 'name' => 'string', 192 214 'icon' => 'string', 215 + 'image' => 'optional string', 193 216 'special' => 'optional string', 194 217 'disabled' => 'optional bool', 195 218 'default' => 'optional bool', ··· 238 261 } 239 262 240 263 $is_disabled = idx($value, 'disabled'); 264 + 265 + if (idx($value, 'image')) { 266 + $builtin = idx($value, 'image'); 267 + $builtin_map = id(new PhabricatorFilesOnDiskBuiltinFile()) 268 + ->getProjectBuiltinFiles(); 269 + $builtin_map = array_flip($builtin_map); 270 + 271 + $root = dirname(phutil_get_library_root('phabricator')); 272 + $image = $root.'/resources/builtin/projects/'.$builtin; 273 + 274 + if (!array_key_exists($image, $builtin_map)) { 275 + throw new Exception( 276 + pht( 277 + 'The project image ("%s") specified for ("%s") '. 278 + 'was not found in the folder "resources/builtin/projects/".', 279 + $builtin, 280 + $key)); 281 + } 282 + } 241 283 242 284 if (idx($value, 'default')) { 243 285 if ($default === null) {
+4 -8
src/applications/project/query/PhabricatorProjectQuery.php
··· 358 358 359 359 protected function didFilterPage(array $projects) { 360 360 if ($this->needImages) { 361 - $default = null; 362 - 363 361 $file_phids = mpull($projects, 'getProfileImagePHID'); 364 362 $file_phids = array_filter($file_phids); 365 363 if ($file_phids) { ··· 376 374 foreach ($projects as $project) { 377 375 $file = idx($files, $project->getProfileImagePHID()); 378 376 if (!$file) { 379 - if (!$default) { 380 - $default = PhabricatorFile::loadBuiltin( 381 - $this->getViewer(), 382 - 'project.png'); 383 - } 384 - $file = $default; 377 + $builtin = PhabricatorProjectIconSet::getIconImage( 378 + $project->getIcon()); 379 + $file = PhabricatorFile::loadBuiltin($this->getViewer(), 380 + 'projects/'.$builtin); 385 381 } 386 382 $project->attachProfileImageFile($file); 387 383 }