Differential D17451 Diff 43379 src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
| <?php | <?php | ||||
| final class PhabricatorEditEngineSubtype | final class PhabricatorEditEngineSubtype | ||||
| extends Phobject { | extends Phobject { | ||||
| const SUBTYPE_DEFAULT = 'default'; | const SUBTYPE_DEFAULT = 'default'; | ||||
| private $key; | private $key; | ||||
| private $name; | private $name; | ||||
| private $icon; | |||||
| private $tagText; | |||||
| private $color; | |||||
| public function setKey($key) { | public function setKey($key) { | ||||
| $this->key = $key; | $this->key = $key; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getKey() { | public function getKey() { | ||||
| return $this->key; | return $this->key; | ||||
| } | } | ||||
| public function setName($name) { | public function setName($name) { | ||||
| $this->name = $name; | $this->name = $name; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getName() { | public function getName() { | ||||
| return $this->name; | return $this->name; | ||||
| } | } | ||||
| public function setIcon($icon) { | |||||
| $this->icon = $icon; | |||||
| return $this; | |||||
| } | |||||
| public function getIcon() { | public function getIcon() { | ||||
| return 'fa-drivers-license-o'; | return $this->icon; | ||||
| } | |||||
| public function setTagText($text) { | |||||
| $this->tagText = $text; | |||||
| return $this; | |||||
| } | |||||
| public function getTagText() { | |||||
| return $this->tagText; | |||||
| } | |||||
| public function setColor($color) { | |||||
| $this->color = $color; | |||||
| return $this; | |||||
| } | |||||
| public function getColor() { | |||||
| return $this->color; | |||||
| } | |||||
| public function hasTagView() { | |||||
| return (bool)strlen($this->getTagText()); | |||||
| } | |||||
| public function newTagView() { | |||||
| $view = id(new PHUITagView()) | |||||
| ->setType(PHUITagView::TYPE_OUTLINE) | |||||
| ->setName($this->getTagText()); | |||||
| $color = $this->getColor(); | |||||
| if ($color) { | |||||
| $view->setColor($color); | |||||
| } | |||||
| return $view; | |||||
| } | } | ||||
| public static function validateSubtypeKey($subtype) { | public static function validateSubtypeKey($subtype) { | ||||
| if (strlen($subtype) > 64) { | if (strlen($subtype) > 64) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Subtype "%s" is not valid: subtype keys must be no longer than '. | 'Subtype "%s" is not valid: subtype keys must be no longer than '. | ||||
| '64 bytes.', | '64 bytes.', | ||||
| Show All 27 Lines | public static function validateConfiguration($config) { | ||||
| $map = array(); | $map = array(); | ||||
| foreach ($config as $value) { | foreach ($config as $value) { | ||||
| PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
| $value, | $value, | ||||
| array( | array( | ||||
| 'key' => 'string', | 'key' => 'string', | ||||
| 'name' => 'string', | 'name' => 'string', | ||||
| 'tag' => 'optional string', | |||||
| 'color' => 'optional string', | |||||
| 'icon' => 'optional string', | |||||
| )); | )); | ||||
| $key = $value['key']; | $key = $value['key']; | ||||
| self::validateSubtypeKey($key); | self::validateSubtypeKey($key); | ||||
| if (isset($map[$key])) { | if (isset($map[$key])) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| Show All 25 Lines | final class PhabricatorEditEngineSubtype | ||||
| public static function newSubtypeMap(array $config) { | public static function newSubtypeMap(array $config) { | ||||
| $map = array(); | $map = array(); | ||||
| foreach ($config as $entry) { | foreach ($config as $entry) { | ||||
| $key = $entry['key']; | $key = $entry['key']; | ||||
| $name = $entry['name']; | $name = $entry['name']; | ||||
| $map[$key] = id(new self()) | $tag_text = idx($entry, 'tag'); | ||||
| if ($tag_text === null) { | |||||
| if ($key != self::SUBTYPE_DEFAULT) { | |||||
| $tag_text = phutil_utf8_strtoupper($name); | |||||
| } | |||||
| } | |||||
| $color = idx($entry, 'color', 'blue'); | |||||
| $icon = idx($entry, 'icon', 'fa-drivers-license-o'); | |||||
| $subtype = id(new self()) | |||||
| ->setKey($key) | ->setKey($key) | ||||
| ->setName($name); | ->setName($name) | ||||
| ->setTagText($tag_text) | |||||
| ->setIcon($icon); | |||||
| if ($color) { | |||||
| $subtype->setColor($color); | |||||
| } | |||||
| $map[$key] = $subtype; | |||||
| } | } | ||||
| return $map; | return $map; | ||||
| } | } | ||||
| } | } | ||||