Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/engine/PhabricatorProfilePanelEngine.php
Show First 20 Lines • Show All 885 Lines • ▼ Show 20 Lines | if ($configuration->isDefault()) { | ||||
return $controller->newDialog() | return $controller->newDialog() | ||||
->setTitle(pht('Already Default')) | ->setTitle(pht('Already Default')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'This item is already set as the default item for this menu.')) | 'This item is already set as the default item for this menu.')) | ||||
->addCancelButton($done_uri); | ->addCancelButton($done_uri); | ||||
} | } | ||||
$type_visibility = | if ($request->isFormPost()) { | ||||
PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY; | $key = $configuration->getID(); | ||||
if (!$key) { | |||||
$key = $configuration->getBuiltinKey(); | |||||
} | |||||
$v_visible = PhabricatorProfilePanelConfiguration::VISIBILITY_VISIBLE; | $this->adjustDefault($key); | ||||
$v_default = PhabricatorProfilePanelConfiguration::VISIBILITY_DEFAULT; | |||||
return id(new AphrontRedirectResponse()) | |||||
->setURI($done_uri); | |||||
} | |||||
return $controller->newDialog() | |||||
->setTitle(pht('Make Default')) | |||||
->appendParagraph( | |||||
pht( | |||||
'Set this item as the default for this menu? Users arriving on '. | |||||
'this page will be shown the content of this item by default.')) | |||||
->addCancelButton($done_uri) | |||||
->addSubmitButton(pht('Make Default')); | |||||
} | |||||
protected function newPanel() { | |||||
return PhabricatorProfilePanelConfiguration::initializeNewBuiltin(); | |||||
} | |||||
public function adjustDefault($key) { | |||||
$controller = $this->getController(); | |||||
$request = $controller->getRequest(); | |||||
$viewer = $request->getViewer(); | |||||
$panels = $this->loadPanels(); | |||||
// To adjust the default panel, we first change any existing panels that | |||||
// are marked as defaults to "visible", then make the new default panel | |||||
// the default. | |||||
$default = array(); | |||||
$visible = array(); | |||||
if ($request->isFormPost()) { | |||||
// First, mark any existing default panels as merely visible. | |||||
foreach ($panels as $panel) { | foreach ($panels as $panel) { | ||||
$builtin_key = $panel->getBuiltinKey(); | |||||
$id = $panel->getID(); | |||||
$is_target = | |||||
(($builtin_key !== null) && ($builtin_key === $key)) || | |||||
(($id !== null) && ($id === (int)$key)); | |||||
if ($is_target) { | |||||
if (!$panel->isDefault()) { | if (!$panel->isDefault()) { | ||||
continue; | $default[] = $panel; | ||||
} | |||||
} else { | |||||
if ($panel->isDefault()) { | |||||
$visible[] = $panel; | |||||
} | |||||
} | |||||
} | } | ||||
$xactions = array(); | $type_visibility = | ||||
PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY; | |||||
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction()) | $v_visible = PhabricatorProfilePanelConfiguration::VISIBILITY_VISIBLE; | ||||
->setTransactionType($type_visibility) | $v_default = PhabricatorProfilePanelConfiguration::VISIBILITY_DEFAULT; | ||||
->setNewValue($v_visible); | |||||
$editor = id(new PhabricatorProfilePanelEditor()) | $apply = array( | ||||
->setContentSourceFromRequest($request) | array($v_visible, $visible), | ||||
->setActor($viewer) | array($v_default, $default), | ||||
->setContinueOnMissingFields(true) | ); | ||||
->setContinueOnNoEffect(true) | |||||
->applyTransactions($panel, $xactions); | |||||
} | |||||
// Now, make this panel the default. | foreach ($apply as $group) { | ||||
list($value, $panels) = $group; | |||||
foreach ($panels as $panel) { | |||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction()) | $xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction()) | ||||
->setTransactionType($type_visibility) | ->setTransactionType($type_visibility) | ||||
->setNewValue($v_default); | ->setNewValue($value); | ||||
$editor = id(new PhabricatorProfilePanelEditor()) | $editor = id(new PhabricatorProfilePanelEditor()) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->applyTransactions($configuration, $xactions); | ->applyTransactions($panel, $xactions); | ||||
return id(new AphrontRedirectResponse()) | |||||
->setURI($done_uri); | |||||
} | } | ||||
return $controller->newDialog() | |||||
->setTitle(pht('Make Default')) | |||||
->appendParagraph( | |||||
pht( | |||||
'Set this item as the default for this menu? Users arriving on '. | |||||
'this page will be shown the content of this item by default.')) | |||||
->addCancelButton($done_uri) | |||||
->addSubmitButton(pht('Make Default')); | |||||
} | } | ||||
protected function newPanel() { | return $this; | ||||
return PhabricatorProfilePanelConfiguration::initializeNewBuiltin(); | |||||
} | } | ||||
} | } |