Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorSettingsPanel.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Defines a settings panel. Settings panels appear in the Settings application, | * Defines a settings panel. Settings panels appear in the Settings application, | ||||
| * and behave like lightweight controllers -- generally, they render some sort | * and behave like lightweight controllers -- generally, they render some sort | ||||
| * of form with options in it, and then update preferences when the user | * of form with options in it, and then update preferences when the user | ||||
| * submits the form. By extending this class, you can add new settings | * submits the form. By extending this class, you can add new settings | ||||
| * panels. | * panels. | ||||
| * | * | ||||
| * NOTE: This stuff is new and might not be completely stable. | |||||
| * | |||||
| * @task config Panel Configuration | * @task config Panel Configuration | ||||
| * @task panel Panel Implementation | * @task panel Panel Implementation | ||||
| * @task internal Internals | * @task internal Internals | ||||
| */ | */ | ||||
| abstract class PhabricatorSettingsPanel extends Phobject { | abstract class PhabricatorSettingsPanel extends Phobject { | ||||
| private $user; | private $user; | ||||
| private $viewer; | private $viewer; | ||||
| Show All 38 Lines | final public function setNavigation(AphrontSideNavFilterView $navigation) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function getNavigation() { | final public function getNavigation() { | ||||
| return $this->navigation; | return $this->navigation; | ||||
| } | } | ||||
| final public static function getAllPanels() { | final public static function getAllPanels() { | ||||
| return id(new PhutilClassMapQuery()) | $panels = id(new PhutilClassMapQuery()) | ||||
| ->setAncestorClass(__CLASS__) | ->setAncestorClass(__CLASS__) | ||||
| ->setUniqueMethod('getPanelKey') | ->setUniqueMethod('getPanelKey') | ||||
| ->setSortMethod('getPanelSortKey') | |||||
| ->execute(); | ->execute(); | ||||
| return msortv($panels, 'getPanelOrderVector'); | |||||
| } | |||||
| final public static function getAllDisplayPanels() { | |||||
| $panels = array(); | |||||
| $groups = PhabricatorSettingsPanelGroup::getAllPanelGroupsWithPanels(); | |||||
| foreach ($groups as $group) { | |||||
| foreach ($group->getPanels() as $key => $panel) { | |||||
| $panels[$key] = $panel; | |||||
| } | |||||
| } | |||||
| return $panels; | |||||
| } | |||||
| final public function getPanelGroup() { | |||||
| $group_key = $this->getPanelGroupKey(); | |||||
| $groups = PhabricatorSettingsPanelGroup::getAllPanelGroupsWithPanels(); | |||||
| $group = idx($groups, $group_key); | |||||
| if (!$group) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'No settings panel group with key "%s" exists!', | |||||
| $group_key)); | |||||
| } | |||||
| return $group; | |||||
| } | } | ||||
| /* -( Panel Configuration )------------------------------------------------ */ | /* -( Panel Configuration )------------------------------------------------ */ | ||||
| /** | /** | ||||
| * Return a unique string used in the URI to identify this panel, like | * Return a unique string used in the URI to identify this panel, like | ||||
| Show All 13 Lines | /* -( Panel Configuration )------------------------------------------------ */ | ||||
| * | * | ||||
| * @return string Human-readable panel name. | * @return string Human-readable panel name. | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| abstract public function getPanelName(); | abstract public function getPanelName(); | ||||
| /** | /** | ||||
| * Return a human-readable group name for this panel. For instance, if you | * Return a panel group key constant for this panel. | ||||
| * had several related panels like "Volume Settings" and | |||||
| * "Microphone Settings", you might put them in a group called "Audio". | |||||
| * | |||||
| * When displayed, panels are grouped with other panels that have the same | |||||
| * group name. | |||||
| * | * | ||||
| * @return string Human-readable panel group name. | * @return const Panel group key. | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| abstract public function getPanelGroup(); | abstract public function getPanelGroupKey(); | ||||
| /** | /** | ||||
| * Return false to prevent this panel from being displayed or used. You can | * Return false to prevent this panel from being displayed or used. You can | ||||
| * do, e.g., configuration checks here, to determine if the feature your | * do, e.g., configuration checks here, to determine if the feature your | ||||
| * panel controls is unavailble in this install. By default, all panels are | * panel controls is unavailble in this install. By default, all panels are | ||||
| * enabled. | * enabled. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Generates a key to sort the list of panels. | * Generates a key to sort the list of panels. | ||||
| * | * | ||||
| * @return string Sortable key. | * @return string Sortable key. | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| final public function getPanelSortKey() { | final public function getPanelOrderVector() { | ||||
| return sprintf( | return id(new PhutilSortVector()) | ||||
| '%s'.chr(255).'%s', | ->addString($this->getPanelName()); | ||||
| $this->getPanelGroup(), | |||||
| $this->getPanelName()); | |||||
| } | } | ||||
| } | } | ||||