Perforce Chronicle 2012.2/486814
API Documentation

Content_Form_Decorator_DisplayFileLink Class Reference

Display link tag for associated file. More...

Inheritance diagram for Content_Form_Decorator_DisplayFileLink:
Content_Form_Decorator_DisplayImage

List of all members.

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.

Detailed Description

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.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Content_Form_Decorator_DisplayFileLink::_renderHtmlTag ( label,
params 
) [protected]

Produce html tag for current element and given label.

Produces a link (anchor tag).

Parameters:
string$labelthe label to include in the tag.
array$paramsthe paramaters to provide to the Uri function
Returns:
string the rendered html tag.

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.

Parameters:
string$contentThe content to render.
Returns:
string
    {
        $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;
        }
    }

Member Data Documentation


The documentation for this class was generated from the following file: