getRequest(); $user = $request->getUser(); $preferences = $user->loadPreferences(); if ($request->isFormPost()) { $monospaced = $request->getStr( PhabricatorUserPreferences::PREFERENCE_MONOSPACED); // Prevent the user from doing stupid things. $monospaced = preg_replace('/[^a-z0-9 ,"]+/i', '', $monospaced); $pref_dict = array( PhabricatorUserPreferences::PREFERENCE_TITLES => $request->getStr(PhabricatorUserPreferences::PREFERENCE_TITLES), PhabricatorUserPreferences::PREFERENCE_MONOSPACED => $monospaced); $preferences->setPreferences($pref_dict); $preferences->save(); return id(new AphrontRedirectResponse()) ->setURI('/preferences/?saved=true'); } $example_string = <<setAction('/preferences/') ->setUser($user) ->appendChild( id(new AphrontFormSelectControl()) ->setLabel('Page Titles') ->setName(PhabricatorUserPreferences::PREFERENCE_TITLES) ->setValue($preferences->getPreference( PhabricatorUserPreferences::PREFERENCE_TITLES)) ->setOptions( array( 'glyph' => "In page titles, show Tool names as unicode glyphs: \xE2\x9A\x99", 'text' => 'In page titles, show Tool names as plain text: [Differential]', ))) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Monospaced Font') ->setName(PhabricatorUserPreferences::PREFERENCE_MONOSPACED) ->setCaption( 'Overrides default fonts in tools like Differential. '. '(Default: 10px "Menlo", "Consolas", "Monaco", '. 'monospace)') ->setValue($preferences->getPreference( PhabricatorUserPreferences::PREFERENCE_MONOSPACED))) ->appendChild( id(new AphrontFormMarkupControl()) ->setValue( '
'.
          phutil_escape_html($example_string).
          '
')) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Save Preferences')); $panel = new AphrontPanelView(); $panel->appendChild($form); $error_view = null; if ($request->getStr('saved') === 'true') { $error_view = id(new AphrontErrorView()) ->setTitle('Preferences Saved') ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) ->setErrors(array('Your preferences have been saved.')); } return $this->buildStandardPageResponse( array( $error_view, $panel, ), array( 'title' => 'Edit Preferences', )); } }