diff --git a/fieldtype_templates/Status.column.php b/fieldtype_templates/Status.column.php new file mode 100644 index 0000000..3978732 --- /dev/null +++ b/fieldtype_templates/Status.column.php @@ -0,0 +1,14 @@ +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'); +}; diff --git a/fieldtype_templates/StripeBuyLinks.column.php b/fieldtype_templates/StripeBuyLinks.column.php new file mode 100644 index 0000000..45ac4a4 --- /dev/null +++ b/fieldtype_templates/StripeBuyLinks.column.php @@ -0,0 +1,41 @@ +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[] = '' + . htmlspecialchars($label, ENT_QUOTES, 'UTF-8') . ''; + } + } + + return implode('
', $links); +};