Differential D20810 Diff 49617 src/applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | final class PhabricatorEditEngineSubtypeMap | ||||
public function newDatasource() { | public function newDatasource() { | ||||
if (!$this->datasource) { | if (!$this->datasource) { | ||||
throw new PhutilInvalidStateException('setDatasource'); | throw new PhutilInvalidStateException('setDatasource'); | ||||
} | } | ||||
return clone($this->datasource); | return clone($this->datasource); | ||||
} | } | ||||
public function getMutationMap($source_key) { | |||||
return mpull($this->getMutations($source_key), 'getName'); | |||||
} | |||||
public function getMutations($source_key) { | |||||
$mutations = $this->subtypes; | |||||
$subtype = idx($this->subtypes, $source_key); | |||||
if ($subtype) { | |||||
$map = $subtype->getMutations(); | |||||
if ($map !== null) { | |||||
$map = array_fuse($map); | |||||
foreach ($mutations as $key => $mutation) { | |||||
if ($key === $source_key) { | |||||
// This is the current subtype, so we always want to show it. | |||||
continue; | |||||
} | |||||
if (isset($map[$key])) { | |||||
// This is an allowed mutation, so keep it. | |||||
continue; | |||||
} | |||||
// Discard other subtypes as mutation options. | |||||
unset($mutations[$key]); | |||||
} | |||||
} | |||||
} | |||||
// If the only available mutation is the current subtype, treat this like | |||||
// no mutations are available. | |||||
if (array_keys($mutations) === array($source_key)) { | |||||
$mutations = array(); | |||||
} | |||||
return $mutations; | |||||
} | |||||
public function getCreateFormsForSubtype( | public function getCreateFormsForSubtype( | ||||
PhabricatorEditEngine $edit_engine, | PhabricatorEditEngine $edit_engine, | ||||
PhabricatorEditEngineSubtypeInterface $object) { | PhabricatorEditEngineSubtypeInterface $object) { | ||||
$subtype_key = $object->getEditEngineSubtype(); | $subtype_key = $object->getEditEngineSubtype(); | ||||
$subtype = $this->getSubtype($subtype_key); | $subtype = $this->getSubtype($subtype_key); | ||||
$select_identifiers = $subtype->getChildFormIdentifiers(); | $select_identifiers = $subtype->getChildFormIdentifiers(); | ||||
Show All 34 Lines |