Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions fieldtype_templates/Status.column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Output template for column: Status (published / unpublished / hidden)
*
* Column realName must be the page property "status".
* $value is the int bitmask returned by $page->get('status').
*/
return function($value, $config = []) {
$status = (int) $value;
$labels = [];
$labels[] = ($status & Page::statusUnpublished) ? 'unpublished' : 'published';
if ($status & Page::statusHidden) $labels[] = 'hidden';
return htmlspecialchars(implode(', ', $labels), ENT_QUOTES, 'UTF-8');
};
41 changes: 41 additions & 0 deletions fieldtype_templates/StripeBuyLinks.column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Output template for column: Stripe Buy Links
*
* Column realName must be the RepeaterMatrix field "elements".
* $value is the RepeaterMatrixPageArray returned by $page->get('elements').
*
* Iterates matrix items, finds a sub-repeater named "buttons" containing
* fields "link" and "label", keeps only URLs that start with
* "https://buy.stripe", deduplicates by URL (first occurrence wins) and
* renders them as anchor tags using "label" as link text.
*/
return function($value, $config = []) {
if (!$value || !is_iterable($value)) return '';

$links = [];
$seen = [];
foreach ($value as $item) {
$buttons = $item->get('buttons');
if (!$buttons || !is_iterable($buttons)) continue;
foreach ($buttons as $btn) {
$url = method_exists($btn, 'getUnformatted')
? (string) $btn->getUnformatted('link')
: (string) $btn->get('link');
$url = trim($url);
if ($url === '' || stripos($url, 'https://buy.stripe') !== 0) continue;
if (isset($seen[$url])) continue;
$seen[$url] = true;
$label = method_exists($btn, 'getUnformatted')
? (string) $btn->getUnformatted('label')
: (string) $btn->get('label');
$label = trim($label);
if ($label === '') $label = $url;
$links[] = '<a href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '"'
. ' target="_blank" rel="noopener">'
. htmlspecialchars($label, ENT_QUOTES, 'UTF-8') . '</a>';
}
}

return implode('<br>', $links);
};