Make server components of inline comment content handling state-oriented
Summary: Ref T13513. Introduce a formal server-side content state object so the whole state can be saved and restored to the drafts table, read from the request, etc. Test Plan: Created and edited inlines. Reloaded drafts with edits. Submitted normal and editing comments. Grepped for affected symbols. Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21275
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
final class PhabricatorDiffInlineCommentContentState
|
||||
extends PhabricatorInlineCommentContentState {
|
||||
|
||||
private $hasSuggestion = false;
|
||||
private $suggestionText = '';
|
||||
|
||||
public function isEmptyContentState() {
|
||||
if (!parent::isEmptyContentState()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getContentHasSuggestion()) {
|
||||
if (strlen($this->getSuggestionText())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setContentSuggestionText($suggestion_text) {
|
||||
$this->suggestionText = $suggestion_text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContentSuggestionText() {
|
||||
return $this->suggestionText;
|
||||
}
|
||||
|
||||
public function setContentHasSuggestion($has_suggestion) {
|
||||
$this->hasSuggestion = $has_suggestion;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContentHasSuggestion() {
|
||||
return $this->hasSuggestion;
|
||||
}
|
||||
|
||||
public function newStorageMap() {
|
||||
return parent::writeStorageMap() + array(
|
||||
'hasSuggestion' => $this->getContentHasSuggestion(),
|
||||
'suggestionText' => $this->getContentSuggestionText(),
|
||||
);
|
||||
}
|
||||
|
||||
public function readStorageMap(array $map) {
|
||||
$result = parent::readStorageMap($map);
|
||||
|
||||
$has_suggestion = (bool)idx($map, 'hasSuggestion');
|
||||
$this->setContentHasSuggestion($has_suggestion);
|
||||
|
||||
$suggestion_text = (string)idx($map, 'suggestionText');
|
||||
$this->setContentSuggestionText($suggestion_text);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function newStorageMapFromRequest(AphrontRequest $request) {
|
||||
$map = parent::newStorageMapFromRequest($request);
|
||||
|
||||
$map['hasSuggestion'] = (bool)$request->getBool('hasSuggestion');
|
||||
$map['suggestionText'] = (string)$request->getStr('suggestionText');
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user