mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-20 11:41:08 +01:00
Have AphrontView implement PhutilSafeHTMLProducerInterface
Summary: Allows views to work like tags. Test Plan: Implemented a few completely arbitrary render() / singleView simplifications. I just picked some that were easy to test. I'll do a more thorough pass on this in a followup; these calls don't really hurt anything. Reviewers: chad, vrana Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D5306
This commit is contained in:
parent
25738e78a1
commit
5e41ead7c7
6 changed files with 32 additions and 22 deletions
|
@ -1652,7 +1652,11 @@ phutil_register_library_map(array(
|
|||
'AphrontTokenizerTemplateView' => 'AphrontView',
|
||||
'AphrontTypeaheadTemplateView' => 'AphrontView',
|
||||
'AphrontUsageException' => 'AphrontException',
|
||||
'AphrontView' => 'Phobject',
|
||||
'AphrontView' =>
|
||||
array(
|
||||
0 => 'Phobject',
|
||||
1 => 'PhutilSafeHTMLProducerInterface',
|
||||
),
|
||||
'AphrontWebpageResponse' => 'AphrontHTMLResponse',
|
||||
'AuditPeopleMenuEventListener' => 'PhutilEventListener',
|
||||
'CelerityPhabricatorResourceController' => 'CelerityResourceController',
|
||||
|
|
|
@ -54,7 +54,7 @@ final class PhabricatorCalendarBrowseController
|
|||
$nav->appendChild(
|
||||
array(
|
||||
$this->getNoticeView(),
|
||||
hsprintf('<div style="padding: 20px;">%s</div>', $month_view->render()),
|
||||
hsprintf('<div style="padding: 20px;">%s</div>', $month_view),
|
||||
));
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
|
|
|
@ -55,11 +55,10 @@ final class DifferentialInlineCommentEditView extends AphrontView {
|
|||
'method' => 'POST',
|
||||
'sigil' => 'inline-edit-form',
|
||||
),
|
||||
$this->renderSingleView(
|
||||
array(
|
||||
$this->renderInputs(),
|
||||
$this->renderBody(),
|
||||
)));
|
||||
));
|
||||
|
||||
return hsprintf(
|
||||
'<table>'.
|
||||
|
@ -130,12 +129,11 @@ final class DifferentialInlineCommentEditView extends AphrontView {
|
|||
array(
|
||||
'class' => 'differential-inline-comment-edit-buttons',
|
||||
),
|
||||
$this->renderSingleView(
|
||||
array(
|
||||
$formatting,
|
||||
$buttons,
|
||||
phutil_tag('div', array('style' => 'clear: both'), ''),
|
||||
)));
|
||||
));
|
||||
|
||||
return javelin_tag(
|
||||
'div',
|
||||
|
@ -148,12 +146,11 @@ final class DifferentialInlineCommentEditView extends AphrontView {
|
|||
'length' => $this->length,
|
||||
),
|
||||
),
|
||||
$this->renderSingleView(
|
||||
array(
|
||||
$title,
|
||||
$body,
|
||||
$edit,
|
||||
)));
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ from XSS and render correctly. Broadly:
|
|||
- Combine elements with arrays, not string concatenation.
|
||||
- @{class:AphrontView} subclasses should return a
|
||||
@{class@libphutil:PhutilSafeHTML} object from their `render()` method.
|
||||
- @{class:AphrontView} subclasses act like tags when rendering.
|
||||
- @{function:pht} has some special rules.
|
||||
- There are some other things that you should be aware of.
|
||||
- Do not use @{function:phutil_render_tag} or @{function:javelin_render_tag},
|
||||
|
@ -124,6 +125,10 @@ return `phutil_tag()` or `javelin_tag()`:
|
|||
|
||||
return phutil_tag('div', ...);
|
||||
|
||||
You can use an @{class:AphrontView} subclass like you would a tag:
|
||||
|
||||
phutil_tag('div', array(), $view);
|
||||
|
||||
= Internationalization: pht() =
|
||||
|
||||
The @{function:pht} function has some special rules. If any input to
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
abstract class AphrontView extends Phobject {
|
||||
abstract class AphrontView extends Phobject
|
||||
implements PhutilSafeHTMLProducerInterface {
|
||||
|
||||
protected $user;
|
||||
protected $children = array();
|
||||
|
@ -65,4 +66,8 @@ abstract class AphrontView extends Phobject {
|
|||
|
||||
abstract public function render();
|
||||
|
||||
public function producePhutilSafeHTML() {
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -145,8 +145,7 @@ final class PhabricatorPropertyListView extends AphrontView {
|
|||
|
||||
$shortcuts = null;
|
||||
if ($this->hasKeyboardShortcuts) {
|
||||
$shortcuts =
|
||||
id(new AphrontKeyboardShortcutsAvailableView())->render();
|
||||
$shortcuts = new AphrontKeyboardShortcutsAvailableView();
|
||||
}
|
||||
|
||||
return array(
|
||||
|
|
Loading…
Reference in a new issue