*/
protected $elementClass;
/**
* @param class-string<\YahnisElsts\AdminMenuEditor\Customizable\Controls\UiElement> $elementClass
* @param array $params
*/
protected function __construct($elementClass, $params = array()) {
$this->elementClass = $elementClass;
$this->params = $params;
}
protected static function buildItems($items, $preserveKeys = false) {
$results = array();
foreach ($items as $key => $item) {
if ( is_array($item) ) {
//Flatten nested arrays of buildable things.
$results = array_merge($results, self::buildItems($item, $preserveKeys));
continue;
}
if ( $item instanceof ElementBuilder ) {
$item = $item->build();
} elseif ( !($item instanceof UiElement) ) {
$typeString = is_object($item) ? get_class($item) : gettype($item);
throw new \InvalidArgumentException(
'Invalid item type for an element builder: ' . $typeString
);
}
if ( $preserveKeys ) {
$results[$key] = $item;
} else {
$results[] = $item;
}
}
return $results;
}
public function id($string) {
$this->params['id'] = $string;
return $this;
}
public function getCustomId() {
return isset($this->params['id']) ? $this->params['id'] : null;
}
/**
* @param string|callable $textOrCallback
* @return $this
*/
public function description($textOrCallback) {
$this->params['description'] = $textOrCallback;
return $this;
}
public function classes(...$cssClassNames) {
return $this->addItemsToArrayParam('classes', $cssClassNames);
}
/**
* Add CSS class names if their values are truthy.
*
* @param array