1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-24 15:52:41 +01:00
phorge-phorge/src/applications/phriction/storage/PhrictionContent.php
Chad Little 06aa3a0a1b Fix Phriction toc rendering when toc is null
Summary: Removes the exception, maybe there is a better way, but landing this for now. Fixes T9829

Test Plan: Test pages with and without a table of contents

Reviewers: epriestley, avivey

Subscribers: epriestley

Maniphest Tasks: T9829

Differential Revision: https://secure.phabricator.com/D14546
2015-11-22 23:07:16 -08:00

130 lines
2.6 KiB
PHP

<?php
/**
* @task markup Markup Interface
*/
final class PhrictionContent extends PhrictionDAO
implements PhabricatorMarkupInterface {
const MARKUP_FIELD_BODY = 'markup:body';
protected $id;
protected $documentID;
protected $version;
protected $authorPHID;
protected $title;
protected $slug;
protected $content;
protected $description;
protected $changeType;
protected $changeRef;
private $renderedTableOfContents;
public function renderContent(PhabricatorUser $viewer) {
return PhabricatorMarkupEngine::renderOneObject(
$this,
self::MARKUP_FIELD_BODY,
$viewer);
}
protected function getConfiguration() {
return array(
self::CONFIG_COLUMN_SCHEMA => array(
'version' => 'uint32',
'title' => 'sort',
'slug' => 'text128',
'content' => 'text',
'changeType' => 'uint32',
'changeRef' => 'uint32?',
// T6203/NULLABILITY
// This should just be empty if not provided?
'description' => 'text?',
),
self::CONFIG_KEY_SCHEMA => array(
'documentID' => array(
'columns' => array('documentID', 'version'),
'unique' => true,
),
'authorPHID' => array(
'columns' => array('authorPHID'),
),
'slug' => array(
'columns' => array('slug'),
),
),
) + parent::getConfiguration();
}
/* -( Markup Interface )--------------------------------------------------- */
/**
* @task markup
*/
public function getMarkupFieldKey($field) {
if ($this->shouldUseMarkupCache($field)) {
$id = $this->getID();
} else {
$id = PhabricatorHash::digest($this->getMarkupText($field));
}
return "phriction:{$field}:{$id}";
}
/**
* @task markup
*/
public function getMarkupText($field) {
return $this->getContent();
}
/**
* @task markup
*/
public function newMarkupEngine($field) {
return PhabricatorMarkupEngine::newPhrictionMarkupEngine();
}
/**
* @task markup
*/
public function didMarkupText(
$field,
$output,
PhutilMarkupEngine $engine) {
$this->renderedTableOfContents =
PhutilRemarkupHeaderBlockRule::renderTableOfContents($engine);
return phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$output);
}
/**
* @task markup
*/
public function getRenderedTableOfContents() {
return $this->renderedTableOfContents;
}
/**
* @task markup
*/
public function shouldUseMarkupCache($field) {
return (bool)$this->getID();
}
}