<?php
|
namespace JVBase\registrar\fields;
|
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
class RepeaterField extends GroupedField {
|
protected array $fields = [];
|
protected string $add_label = 'Add Row';
|
protected string $row_label = 'New Item';
|
|
public function setAddLabel(string $label):void
|
{
|
$this->add_label = $label;
|
}
|
public function getAddLabel():string
|
{
|
return $this->add_label;
|
}
|
protected function checkFieldVariables(string $variables):bool
|
{
|
if (!str_contains($variables, '{{')) {
|
return false;
|
}
|
$fields = array_filter(array_map(function($field) { return str_replace('}}','',$field);}, explode('{{',$variables)));
|
foreach ($fields as $field) {
|
if (!array_key_exists($field, $this->fields)) {
|
error_log('['.(new \ReflectionClass($this))->getShortName().']Invalid field attempted: '.$field);
|
return false;
|
}
|
}
|
return true;
|
}
|
public function setRowLabel(string $label):void
|
{
|
if (str_contains($label, '{{')) {
|
if (!$this->checkFieldVariables($label)) {
|
return;
|
}
|
}
|
|
$this->row_label = $label;
|
}
|
public function getRowLabel():string
|
{
|
return $this->row_label;
|
}
|
}
|