Differential D19854 Diff 47435 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 $icon; | ||||
| private $tagText; | private $tagText; | ||||
| private $color; | private $color; | ||||
| private $childSubtypes = array(); | |||||
| private $childIdentifiers = array(); | |||||
| 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; | ||||
| Show All 30 Lines | public function setColor($color) { | ||||
| $this->color = $color; | $this->color = $color; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getColor() { | public function getColor() { | ||||
| return $this->color; | return $this->color; | ||||
| } | } | ||||
| public function setChildSubtypes(array $child_subtypes) { | |||||
| $this->childSubtypes = $child_subtypes; | |||||
| return $this; | |||||
| } | |||||
| public function getChildSubtypes() { | |||||
| return $this->childSubtypes; | |||||
| } | |||||
| public function setChildFormIdentifiers(array $child_identifiers) { | |||||
| $this->childIdentifiers = $child_identifiers; | |||||
| return $this; | |||||
| } | |||||
| public function getChildFormIdentifiers() { | |||||
| return $this->childIdentifiers; | |||||
| } | |||||
| public function hasTagView() { | public function hasTagView() { | ||||
| return (bool)strlen($this->getTagText()); | return (bool)strlen($this->getTagText()); | ||||
| } | } | ||||
| public function newTagView() { | public function newTagView() { | ||||
| $view = id(new PHUITagView()) | $view = id(new PHUITagView()) | ||||
| ->setType(PHUITagView::TYPE_OUTLINE) | ->setType(PHUITagView::TYPE_OUTLINE) | ||||
| ->setName($this->getTagText()); | ->setName($this->getTagText()); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | foreach ($config as $value) { | ||||
| PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
| $value, | $value, | ||||
| array( | array( | ||||
| 'key' => 'string', | 'key' => 'string', | ||||
| 'name' => 'string', | 'name' => 'string', | ||||
| 'tag' => 'optional string', | 'tag' => 'optional string', | ||||
| 'color' => 'optional string', | 'color' => 'optional string', | ||||
| 'icon' => 'optional string', | 'icon' => 'optional string', | ||||
| 'children' => 'optional map<string, wild>', | |||||
| )); | )); | ||||
| $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( | ||||
| 'Subtype configuration is invalid: two subtypes use the same '. | 'Subtype configuration is invalid: two subtypes use the same '. | ||||
| 'key ("%s"). Each subtype must have a unique key.', | 'key ("%s"). Each subtype must have a unique key.', | ||||
| $key)); | $key)); | ||||
| } | } | ||||
| $map[$key] = true; | $map[$key] = true; | ||||
| $name = $value['name']; | $name = $value['name']; | ||||
| if (!strlen($name)) { | if (!strlen($name)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Subtype configuration is invalid: subtype with key "%s" has '. | 'Subtype configuration is invalid: subtype with key "%s" has '. | ||||
| 'no name. Subtypes must have a name.', | 'no name. Subtypes must have a name.', | ||||
| $key)); | $key)); | ||||
| } | } | ||||
| $children = idx($value, 'children'); | |||||
| if ($children) { | |||||
| PhutilTypeSpec::checkMap( | |||||
| $children, | |||||
| array( | |||||
| 'subtypes' => 'optional list<string>', | |||||
| 'forms' => 'optional list<string|int>', | |||||
| )); | |||||
| $child_subtypes = idx($children, 'subtypes'); | |||||
| $child_forms = idx($children, 'forms'); | |||||
| if ($child_subtypes && $child_forms) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Subtype configuration is invalid: subtype with key "%s" '. | |||||
| 'specifies both child subtypes and child forms. Specify one '. | |||||
| 'or the other, but not both.')); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| if (!isset($map[self::SUBTYPE_DEFAULT])) { | if (!isset($map[self::SUBTYPE_DEFAULT])) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Subtype configuration is invalid: there is no subtype defined '. | 'Subtype configuration is invalid: there is no subtype defined '. | ||||
| 'with key "%s". This subtype is required and must be defined.', | 'with key "%s". This subtype is required and must be defined.', | ||||
| self::SUBTYPE_DEFAULT)); | self::SUBTYPE_DEFAULT)); | ||||
| Show All 22 Lines | foreach ($config as $entry) { | ||||
| ->setName($name) | ->setName($name) | ||||
| ->setTagText($tag_text) | ->setTagText($tag_text) | ||||
| ->setIcon($icon); | ->setIcon($icon); | ||||
| if ($color) { | if ($color) { | ||||
| $subtype->setColor($color); | $subtype->setColor($color); | ||||
| } | } | ||||
| $children = idx($entry, 'children', array()); | |||||
| $child_subtypes = idx($children, 'subtypes'); | |||||
| $child_forms = idx($children, 'forms'); | |||||
| if ($child_subtypes) { | |||||
| $subtype->setChildSubtypes($child_subtypes); | |||||
| } | |||||
| if ($child_forms) { | |||||
| $subtype->setChildFormIdentifiers($child_forms); | |||||
| } | |||||
| $map[$key] = $subtype; | $map[$key] = $subtype; | ||||
| } | } | ||||
| return new PhabricatorEditEngineSubtypeMap($map); | return new PhabricatorEditEngineSubtypeMap($map); | ||||
| } | } | ||||
| } | } | ||||