Perforce Chronicle 2012.2/486814
API Documentation
|
Display link tag for associated file. More...
Public Member Functions | |
render ($content) | |
Display download link for element's associated file. | |
Public Attributes | |
const | REPLACE = false |
Protected Member Functions | |
_renderHtmlTag ($label, $params) | |
Produce html tag for current element and given label. |
Display link tag for associated file.
File link is taken to be the download URI for element's associated content record. The element must be content type enhanced to get the associated content.
Content_Form_Decorator_DisplayFileLink::_renderHtmlTag | ( | $ | label, |
$ | params | ||
) | [protected] |
Produce html tag for current element and given label.
Produces a link (anchor tag).
string | $label | the label to include in the tag. |
array | $params | the paramaters to provide to the Uri function |
Reimplemented in Content_Form_Decorator_DisplayImage.
{ $record = $this->getElement()->getContentRecord(); $uri = $record->getUri('download', $params); return "<a href='" . htmlentities($uri) . "'>" . htmlentities($label) . "</a>"; }
Content_Form_Decorator_DisplayFileLink::render | ( | $ | content | ) |
Display download link for element's associated file.
string | $content | The content to render. |
{ $element = $this->getElement(); $label = $element->getLabel() ? : $element->getName(); // element must have an associated content record. if ($element instanceof P4Cms_Content_EnhancedElementInterface && $element->getContentRecord() instanceof P4Cms_Content ) { $record = $element->getContentRecord(); if ($record->getId() !== null && $element instanceof Content_Form_Element_File) { $info = $record->getFieldMetadata($element->getName()); if (isset($info['filename']) && strlen($info['filename'])) { $label = $info['filename']; } } } else { throw new Content_Exception( "Cannot render download decorator. Element has no associated content record." ); } // early exit if file has no length and no metadata. // @todo possibly optimize this to not read entire value to // check for length (e.g. could check filesize in case // of actual file fields - wouldn't work for traits). $value = $record->getValue($element->getName()); $metadata = $record->getFieldMetadata($element->getName()); if (!strlen($value) && empty($metadata)) { return $content; } // if this field is not the primary file field, pass it in the uri. if ($record->hasFileContentField() && $record->getFileContentField() !== $element->getName() ) { $params = array('field' => $element->getName()); } else { $params = array(); } // include version if decorating a historic revision. if ($record->hasId()) { $file = $record->toP4File(); if (!$file->isHead()) { $params['version'] = $file->getStatus('headRev'); } } $html = $this->_renderHtmlTag($label, $params); switch ($this->getPlacement()) { case self::APPEND: return $content . $html; case self::PREPEND: return $html . $content; default: return $html; } }
const Content_Form_Decorator_DisplayFileLink::REPLACE = false |