/** * @param string $action Permissions action to require to return revision * @return AbstractRevision|null * @throws InvalidDataException */ public function loadTopicTitle($action = 'view') { if ($this->workflow->isNew()) { throw new InvalidDataException('New workflows do not have any related content', 'missing-topic-title'); } if ($this->topicTitle === null) { $found = $this->storage->find('PostRevision', array('rev_type_id' => $this->workflow->getId()), array('sort' => 'rev_id', 'order' => 'DESC', 'limit' => 1)); if (!$found) { throw new InvalidDataException('Every workflow must have an associated topic title', 'missing-topic-title'); } $this->topicTitle = reset($found); // this method loads only title, nothing else; otherwise, you're // looking for loadRootPost $this->topicTitle->setChildren(array()); $this->topicTitle->setDepth(0); $this->topicTitle->setRootPost($this->topicTitle); } if (!$this->permissions->isAllowed($this->topicTitle, $action)) { $this->addError('permissions', $this->getDisallowedErrorMessage($this->topicTitle)); return null; } return $this->topicTitle; }