Differential D18519 Diff 44484 src/applications/config/controller/PhabricatorConfigEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/controller/PhabricatorConfigEditController.php
<?php | <?php | ||||
final class PhabricatorConfigEditController | final class PhabricatorConfigEditController | ||||
extends PhabricatorConfigController { | extends PhabricatorConfigController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$key = $request->getURIData('key'); | $key = $request->getURIData('key'); | ||||
$options = PhabricatorApplicationConfigOptions::loadAllOptions(); | $options = PhabricatorApplicationConfigOptions::loadAllOptions(); | ||||
if (empty($options[$key])) { | if (empty($options[$key])) { | ||||
$ancient = PhabricatorExtraConfigSetupCheck::getAncientConfig(); | $ancient = PhabricatorExtraConfigSetupCheck::getAncientConfig(); | ||||
if (isset($ancient[$key])) { | if (isset($ancient[$key])) { | ||||
$desc = pht( | $desc = pht( | ||||
"This configuration has been removed. You can safely delete ". | "This configuration has been removed. You can safely delete ". | ||||
"it.\n\n%s", | "it.\n\n%s", | ||||
$ancient[$key]); | $ancient[$key]); | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setEncType('multipart/form-data'); | ->setEncType('multipart/form-data'); | ||||
$error_view = null; | $error_view = null; | ||||
if ($errors) { | if ($errors) { | ||||
$error_view = id(new PHUIInfoView()) | $error_view = id(new PHUIInfoView()) | ||||
->setSeverity(PHUIInfoView::SEVERITY_ERROR) | |||||
->setErrors($errors); | ->setErrors($errors); | ||||
} | } | ||||
$status_items = array(); | |||||
if ($option->getHidden()) { | |||||
$message = pht( | |||||
'This configuration is hidden and can not be edited or viewed from '. | |||||
'the web interface.'); | |||||
$status_items[] = id(new PHUIStatusItemView()) | |||||
->setIcon('fa-eye-slash red') | |||||
->setTarget(phutil_tag('strong', array(), pht('Configuration Hidden'))) | |||||
->setNote($message); | |||||
} else if ($option->getLocked()) { | |||||
$message = $option->getLockedMessage(); | |||||
$status_items[] = id(new PHUIStatusItemView()) | |||||
->setIcon('fa-lock red') | |||||
->setTarget(phutil_tag('strong', array(), pht('Configuration Locked'))) | |||||
->setNote($message); | |||||
} | |||||
if ($status_items) { | |||||
$doc_href = PhabricatorEnv::getDoclink( | $doc_href = PhabricatorEnv::getDoclink( | ||||
'Configuration Guide: Locked and Hidden Configuration'); | 'Configuration Guide: Locked and Hidden Configuration'); | ||||
$doc_link = phutil_tag( | $doc_link = phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => $doc_href, | 'href' => $doc_href, | ||||
'target' => '_blank', | 'target' => '_blank', | ||||
), | ), | ||||
pht('Configuration Guide: Locked and Hidden Configuration')); | pht('Learn more about locked and hidden options.')); | ||||
$status_items = array(); | |||||
$tag = null; | |||||
if ($option->getHidden()) { | |||||
$tag = id(new PHUITagView()) | |||||
->setName(pht('Hidden')) | |||||
->setColor(PHUITagView::COLOR_GREY) | |||||
->setBorder(PHUITagView::BORDER_NONE) | |||||
->setType(PHUITagView::TYPE_SHADE); | |||||
$message = pht( | |||||
'This configuration is hidden and can not be edited or viewed from '. | |||||
'the web interface.'); | |||||
$status_items[] = id(new PHUIInfoView()) | |||||
->appendChild(array($message, ' ', $doc_link)); | |||||
} else if ($option->getLocked()) { | |||||
$tag = id(new PHUITagView()) | |||||
->setName(pht('Locked')) | |||||
->setColor(PHUITagView::COLOR_RED) | |||||
->setBorder(PHUITagView::BORDER_NONE) | |||||
->setType(PHUITagView::TYPE_SHADE); | |||||
$status_items[] = id(new PHUIStatusItemView()) | $message = $option->getLockedMessage(); | ||||
->setIcon('fa-book') | $status_items[] = id(new PHUIInfoView()) | ||||
->setTarget(phutil_tag('strong', array(), pht('Learn More'))) | ->appendChild(array($message, ' ', $doc_link)); | ||||
->setNote($doc_link); | |||||
} | } | ||||
if ($option->getHidden() || $option->getLocked()) { | if ($option->getHidden() || $option->getLocked()) { | ||||
$controls = array(); | $controls = array(); | ||||
} else { | } else { | ||||
$controls = $this->renderControls( | $controls = $this->renderControls( | ||||
$option, | $option, | ||||
$display_value, | $display_value, | ||||
Show All 10 Lines | $description = phutil_tag( | ||||
'class' => 'phabricator-remarkup', | 'class' => 'phabricator-remarkup', | ||||
), | ), | ||||
$engine->getOutput($option, 'description')); | $engine->getOutput($option, 'description')); | ||||
$form | $form | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->addHiddenInput('issue', $request->getStr('issue')); | ->addHiddenInput('issue', $request->getStr('issue')); | ||||
if ($status_items) { | |||||
$status_view = id(new PHUIStatusListView()); | |||||
foreach ($status_items as $status_item) { | |||||
$status_view->addItem($status_item); | |||||
} | |||||
$form->appendControl( | |||||
id(new AphrontFormMarkupControl()) | |||||
->setValue($status_view)); | |||||
} | |||||
$description = $option->getDescription(); | $description = $option->getDescription(); | ||||
if (strlen($description)) { | if (strlen($description)) { | ||||
$description_view = new PHUIRemarkupView($viewer, $description); | $description_view = new PHUIRemarkupView($viewer, $description); | ||||
$form | $form | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormMarkupControl()) | id(new AphrontFormMarkupControl()) | ||||
->setLabel(pht('Description')) | ->setLabel(pht('Description')) | ||||
Show All 17 Lines | public function handleRequest(AphrontRequest $request) { | ||||
if (!$option->getLocked()) { | if (!$option->getLocked()) { | ||||
$form->appendChild( | $form->appendChild( | ||||
id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
->addCancelButton($done_uri) | ->addCancelButton($done_uri) | ||||
->setValue(pht('Save Config Entry'))); | ->setValue(pht('Save Config Entry'))); | ||||
} | } | ||||
$current_config = null; | |||||
if (!$option->getHidden()) { | if (!$option->getHidden()) { | ||||
$form->appendChild( | $current_config = $this->renderDefaults($option, $config_entry); | ||||
id(new AphrontFormMarkupControl()) | $current_config = $this->buildConfigBoxView( | ||||
->setLabel(pht('Current Configuration')) | pht('Current Configuration'), | ||||
->setValue($this->renderDefaults($option, $config_entry))); | $current_config); | ||||
} | } | ||||
$examples = $this->renderExamples($option); | $examples = $this->renderExamples($option); | ||||
if ($examples) { | if ($examples) { | ||||
$form->appendChild( | $examples = $this->buildConfigBoxView( | ||||
id(new AphrontFormMarkupControl()) | pht('Examples'), | ||||
->setLabel(pht('Examples')) | $examples); | ||||
->setValue($examples)); | |||||
} | } | ||||
$title = pht('Edit Option: %s', $key); | $title = $key; | ||||
$header_icon = 'fa-pencil'; | |||||
$short = pht('Edit'); | |||||
$form_box = id(new PHUIObjectBoxView()) | |||||
->setHeaderText(pht('Config Option')) | |||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->setForm($form); | |||||
if ($error_view) { | |||||
$form_box->setInfoView($error_view); | |||||
} | |||||
$crumbs = $this->buildApplicationCrumbs(); | |||||
$crumbs->addTextCrumb(pht('Config'), $this->getApplicationURI()); | |||||
$box_header = array(); | |||||
if ($group) { | if ($group) { | ||||
$crumbs->addTextCrumb($group->getName(), $group_uri); | $box_header[] = phutil_tag( | ||||
'a', | |||||
array( | |||||
'href' => $group_uri, | |||||
), | |||||
$group->getName()); | |||||
$box_header[] = " \xC2\xBB "; | |||||
} | } | ||||
$box_header[] = $key; | |||||
$crumbs->addTextCrumb($key, '/config/edit/'.$key); | $form_box = $this->buildConfigBoxView($box_header, $form, $tag); | ||||
$crumbs->setBorder(true); | |||||
$timeline = $this->buildTransactionTimeline( | $timeline = $this->buildTransactionTimeline( | ||||
$config_entry, | $config_entry, | ||||
new PhabricatorConfigTransactionQuery()); | new PhabricatorConfigTransactionQuery()); | ||||
$timeline->setShouldTerminate(true); | $timeline->setShouldTerminate(true); | ||||
$header = id(new PHUIHeaderView()) | $nav = $this->buildSideNavView(); | ||||
->setHeader($title) | $nav->selectFilter($group_uri); | ||||
->setHeaderIcon($header_icon); | |||||
$header = $this->buildHeaderView($title); | |||||
$view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->setFooter($form_box); | ->setNavigation($nav) | ||||
->setFixed(true) | |||||
->setMainColumn(array( | |||||
$error_view, | |||||
$form_box, | |||||
$status_items, | |||||
$examples, | |||||
$current_config, | |||||
)); | |||||
return $this->newPage() | return $this->newPage() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->setCrumbs($crumbs) | |||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
private function readRequest( | private function readRequest( | ||||
PhabricatorConfigOption $option, | PhabricatorConfigOption $option, | ||||
AphrontRequest $request) { | AphrontRequest $request) { | ||||
$type = $option->newOptionType(); | $type = $option->newOptionType(); | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | foreach ($examples as $example) { | ||||
if ($value === null) { | if ($value === null) { | ||||
$value = phutil_tag('em', array(), pht('(empty)')); | $value = phutil_tag('em', array(), pht('(empty)')); | ||||
} else { | } else { | ||||
if (is_array($value)) { | if (is_array($value)) { | ||||
$value = implode("\n", $value); | $value = implode("\n", $value); | ||||
} | } | ||||
} | } | ||||
$table[] = phutil_tag('tr', array(), array( | $table[] = phutil_tag('tr', array('class' => 'column-labels'), array( | ||||
phutil_tag('th', array(), $description), | phutil_tag('th', array(), $description), | ||||
phutil_tag('td', array(), $value), | phutil_tag('td', array(), $value), | ||||
)); | )); | ||||
} | } | ||||
require_celerity_resource('config-options-css'); | require_celerity_resource('config-options-css'); | ||||
return phutil_tag( | return phutil_tag( | ||||
'table', | 'table', | ||||
array( | array( | ||||
'class' => 'config-option-table', | 'class' => 'config-option-table', | ||||
'cellspacing' => '0', | |||||
'cellpadding' => '0', | |||||
), | ), | ||||
$table); | $table); | ||||
} | } | ||||
private function renderDefaults( | private function renderDefaults( | ||||
PhabricatorConfigOption $option, | PhabricatorConfigOption $option, | ||||
PhabricatorConfigEntry $entry) { | PhabricatorConfigEntry $entry) { | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | private function renderDefaults( | ||||
} | } | ||||
require_celerity_resource('config-options-css'); | require_celerity_resource('config-options-css'); | ||||
return phutil_tag( | return phutil_tag( | ||||
'table', | 'table', | ||||
array( | array( | ||||
'class' => 'config-option-table', | 'class' => 'config-option-table', | ||||
'cellspacing' => '0', | |||||
'cellpadding' => '0', | |||||
), | ), | ||||
$table); | $table); | ||||
} | } | ||||
} | } |