1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-14 18:55:56 +02:00

Minor improvements in core MarkupFieldtype class

This commit is contained in:
Ryan Cramer
2019-07-31 09:33:43 -04:00
parent 83369f1173
commit 3cb1f33a97

View File

@@ -56,7 +56,17 @@ class MarkupFieldtype extends WireData implements Module {
* @var bool
*
*/
protected $renderIsUseless = false;
protected $renderIsUseless = false;
/**
* Properties that are potentially linkable to source page in markup
*
* @var array
*
*/
protected $linkableProperties = array(
'name', 'url', 'httpUrl', 'path', 'title',
);
/**
* Construct the MarkupFieldtype
@@ -108,8 +118,8 @@ class MarkupFieldtype extends WireData implements Module {
foreach($value as $page) {
$v = $page->getFormatted($property);
$v = $field->type->markupValue($page, $field, $v);
if($page->viewable()) {
$a[] = "<a href='$page->url'>$v</a>";
if($this->isLinkablePageProperty($page, $property)) {
$a[] = "<a href='$page->url'>$property: $v</a>";
} else {
$a[] = $v;
}
@@ -356,6 +366,20 @@ class MarkupFieldtype extends WireData implements Module {
return $out;
}
/**
* Is the given page property/field name one that should be linked to the source page in output?
*
* @param Page $page
* @param $property
* @return bool
*
*/
protected function isLinkablePageProperty(Page $page, $property) {
if(!in_array($property, $this->linkableProperties)) return false;
if(!$page->viewable($property)) return false;
return true;
}
/**
* The string value of a MarkupFieldtype is always the fully rendered field
*