Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
| Show First 20 Lines • Show All 346 Lines • ▼ Show 20 Lines | foreach ($configurations as $config) { | ||||
| if ($config->getBuiltinKey() == self::EDITENGINECONFIG_DEFAULT) { | if ($config->getBuiltinKey() == self::EDITENGINECONFIG_DEFAULT) { | ||||
| $has_default = true; | $has_default = true; | ||||
| } | } | ||||
| } | } | ||||
| if (!$has_default) { | if (!$has_default) { | ||||
| $first = head($configurations); | $first = head($configurations); | ||||
| if (!$first->getBuiltinKey()) { | if (!$first->getBuiltinKey()) { | ||||
| $first->setBuiltinKey(self::EDITENGINECONFIG_DEFAULT); | $first | ||||
| ->setBuiltinKey(self::EDITENGINECONFIG_DEFAULT) | |||||
| ->setIsDefault(true); | |||||
| if (!strlen($first->getName())) { | if (!strlen($first->getName())) { | ||||
| $first->setName($this->getObjectCreateShortText()); | $first->setName($this->getObjectCreateShortText()); | ||||
| } | } | ||||
| } else { | } else { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'EditEngine ("%s") returned builtin engine configurations, '. | 'EditEngine ("%s") returned builtin engine configurations, '. | ||||
| ▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | final public function buildResponse() { | ||||
| } | } | ||||
| $this->validateObject($object); | $this->validateObject($object); | ||||
| $action = $request->getURIData('editAction'); | $action = $request->getURIData('editAction'); | ||||
| switch ($action) { | switch ($action) { | ||||
| case 'parameters': | case 'parameters': | ||||
| return $this->buildParametersResponse($object); | return $this->buildParametersResponse($object); | ||||
| case 'nodefault': | |||||
| return $this->buildNoDefaultResponse($object); | |||||
| default: | default: | ||||
| return $this->buildEditResponse($object); | return $this->buildEditResponse($object); | ||||
| } | } | ||||
| } | } | ||||
| private function buildCrumbs($object, $final = false) { | private function buildCrumbs($object, $final = false) { | ||||
| $controller = $this->getcontroller(); | $controller = $this->getcontroller(); | ||||
| ▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | private function buildEditFormActions($object) { | ||||
| $actions[] = id(new PhabricatorActionView()) | $actions[] = id(new PhabricatorActionView()) | ||||
| ->setName(pht('Show HTTP Parameters')) | ->setName(pht('Show HTTP Parameters')) | ||||
| ->setIcon('fa-crosshairs') | ->setIcon('fa-crosshairs') | ||||
| ->setHref($this->getEditURI($object, 'parameters/')); | ->setHref($this->getEditURI($object, 'parameters/')); | ||||
| return $actions; | return $actions; | ||||
| } | } | ||||
| final public function addActionToCrumbs(PHUICrumbsView $crumbs) { | |||||
| $viewer = $this->getViewer(); | |||||
| $configs = id(new PhabricatorEditEngineConfigurationQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withEngineKeys(array($this->getEngineKey())) | |||||
| ->withIsDefault(true) | |||||
| ->withIsDisabled(false) | |||||
| ->execute(); | |||||
| $dropdown = null; | |||||
| $disabled = false; | |||||
| $workflow = false; | |||||
| $menu_icon = 'fa-plus-square'; | |||||
| if (!$configs) { | |||||
| if ($viewer->isLoggedIn()) { | |||||
| $disabled = true; | |||||
| } else { | |||||
| // If the viewer isn't logged in, assume they'll get hit with a login | |||||
| // dialog and are likely able to create objects after they log in. | |||||
| $disabled = false; | |||||
| } | |||||
| $workflow = true; | |||||
| $create_uri = $this->getEditURI(null, 'nodefault/'); | |||||
| } else { | |||||
| $config = head($configs); | |||||
| $form_key = $config->getIdentifier(); | |||||
| $create_uri = $this->getEditURI(null, "form/{$form_key}/"); | |||||
| if (count($configs) > 1) { | |||||
| $configs = msort($configs, 'getDisplayName'); | |||||
| $menu_icon = 'fa-caret-square-o-down'; | |||||
| $dropdown = id(new PhabricatorActionListView()) | |||||
| ->setUser($viewer); | |||||
| foreach ($configs as $config) { | |||||
| $form_key = $config->getIdentifier(); | |||||
| $config_uri = $this->getEditURI(null, "form/{$form_key}/"); | |||||
| $item_icon = 'fa-plus'; | |||||
| $dropdown->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName($config->getDisplayName()) | |||||
| ->setIcon($item_icon) | |||||
| ->setHref($config_uri)); | |||||
| } | |||||
| } | |||||
| } | |||||
| $action = id(new PHUIListItemView()) | |||||
| ->setName($this->getObjectCreateShortText()) | |||||
| ->setHref($create_uri) | |||||
| ->setIcon($menu_icon) | |||||
| ->setWorkflow($workflow) | |||||
| ->setDisabled($disabled); | |||||
| if ($dropdown) { | |||||
| $action->setDropdownMenu($dropdown); | |||||
| } | |||||
| $crumbs->addAction($action); | |||||
| } | |||||
| /* -( Responding to HTTP Parameter Requests )------------------------------ */ | /* -( Responding to HTTP Parameter Requests )------------------------------ */ | ||||
| /** | /** | ||||
| * Respond to a request for documentation on HTTP parameters. | * Respond to a request for documentation on HTTP parameters. | ||||
| * | * | ||||
| * @param object Editable object. | * @param object Editable object. | ||||
| Show All 28 Lines | private function buildParametersResponse($object) { | ||||
| return $controller->newPage() | return $controller->newPage() | ||||
| ->setTitle(pht('HTTP Parameters')) | ->setTitle(pht('HTTP Parameters')) | ||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->appendChild($document); | ->appendChild($document); | ||||
| } | } | ||||
| private function buildNoDefaultResponse($object) { | |||||
| $cancel_uri = $this->getObjectCreateCancelURI($object); | |||||
| return $this->getController() | |||||
| ->newDialog() | |||||
| ->setTitle(pht('No Default Create Forms')) | |||||
| ->appendParagraph( | |||||
| pht( | |||||
| 'This application is not configured with any visible, enabled '. | |||||
| 'forms for creating objects.')) | |||||
| ->addCancelButton($cancel_uri); | |||||
| } | |||||
| /* -( Conduit )------------------------------------------------------------ */ | /* -( Conduit )------------------------------------------------------------ */ | ||||
| /** | /** | ||||
| * Respond to a Conduit edit request. | * Respond to a Conduit edit request. | ||||
| * | * | ||||
| * This method accepts a list of transactions to apply to an object, and | * This method accepts a list of transactions to apply to an object, and | ||||
| * either edits an existing object or creates a new one. | * either edits an existing object or creates a new one. | ||||
| ▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines | |||||