Upgrade to 4.0.0
This commit is contained in:
@@ -36,12 +36,8 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Magic getter/caller for any blueprint prop
|
||||
*
|
||||
* @param string $key
|
||||
* @param array|null $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $key, array $arguments = null)
|
||||
public function __call(string $key, array $arguments = null): mixed
|
||||
{
|
||||
return $this->props[$key] ?? null;
|
||||
}
|
||||
@@ -49,7 +45,6 @@ class Blueprint
|
||||
/**
|
||||
* Creates a new blueprint object with the given props
|
||||
*
|
||||
* @param array $props
|
||||
* @throws \Kirby\Exception\InvalidArgumentException If the blueprint model is missing
|
||||
*/
|
||||
public function __construct(array $props)
|
||||
@@ -77,7 +72,8 @@ class Blueprint
|
||||
$props['name'] ??= 'default';
|
||||
|
||||
// normalize and translate the title
|
||||
$props['title'] = $this->i18n($props['title'] ?? ucfirst($props['name']));
|
||||
$props['title'] ??= ucfirst($props['name']);
|
||||
$props['title'] = $this->i18n($props['title']);
|
||||
|
||||
// convert all shortcuts
|
||||
$props = $this->convertFieldsToSections('main', $props);
|
||||
@@ -93,7 +89,7 @@ class Blueprint
|
||||
/**
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
@@ -103,13 +99,11 @@ class Blueprint
|
||||
/**
|
||||
* Converts all column definitions, that
|
||||
* are not wrapped in a tab, into a generic tab
|
||||
*
|
||||
* @param string $tabName
|
||||
* @param array $props
|
||||
* @return array
|
||||
*/
|
||||
protected function convertColumnsToTabs(string $tabName, array $props): array
|
||||
{
|
||||
protected function convertColumnsToTabs(
|
||||
string $tabName,
|
||||
array $props
|
||||
): array {
|
||||
if (isset($props['columns']) === false) {
|
||||
return $props;
|
||||
}
|
||||
@@ -130,13 +124,11 @@ class Blueprint
|
||||
* Converts all field definitions, that are not
|
||||
* wrapped in a fields section into a generic
|
||||
* fields section.
|
||||
*
|
||||
* @param string $tabName
|
||||
* @param array $props
|
||||
* @return array
|
||||
*/
|
||||
protected function convertFieldsToSections(string $tabName, array $props): array
|
||||
{
|
||||
protected function convertFieldsToSections(
|
||||
string $tabName,
|
||||
array $props
|
||||
): array {
|
||||
if (isset($props['fields']) === false) {
|
||||
return $props;
|
||||
}
|
||||
@@ -157,13 +149,11 @@ class Blueprint
|
||||
/**
|
||||
* Converts all sections that are not wrapped in
|
||||
* columns, into a single generic column.
|
||||
*
|
||||
* @param string $tabName
|
||||
* @param array $props
|
||||
* @return array
|
||||
*/
|
||||
protected function convertSectionsToColumns(string $tabName, array $props): array
|
||||
{
|
||||
protected function convertSectionsToColumns(
|
||||
string $tabName,
|
||||
array $props
|
||||
): array {
|
||||
if (isset($props['sections']) === false) {
|
||||
return $props;
|
||||
}
|
||||
@@ -187,7 +177,6 @@ class Blueprint
|
||||
* props is just a string
|
||||
*
|
||||
* @param array|string $props
|
||||
* @return array
|
||||
*/
|
||||
public static function extend($props): array
|
||||
{
|
||||
@@ -221,14 +210,12 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Create a new blueprint for a model
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|null $fallback
|
||||
* @param \Kirby\Cms\Model $model
|
||||
* @return static|null
|
||||
*/
|
||||
public static function factory(string $name, string $fallback = null, Model $model)
|
||||
{
|
||||
public static function factory(
|
||||
string $name,
|
||||
string $fallback = null,
|
||||
ModelWithContent $model
|
||||
): static|null {
|
||||
try {
|
||||
$props = static::load($name);
|
||||
} catch (Exception) {
|
||||
@@ -247,9 +234,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Returns a single field definition by name
|
||||
*
|
||||
* @param string $name
|
||||
* @return array|null
|
||||
*/
|
||||
public function field(string $name): array|null
|
||||
{
|
||||
@@ -258,8 +242,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Returns all field definitions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields(): array
|
||||
{
|
||||
@@ -269,8 +251,6 @@ class Blueprint
|
||||
/**
|
||||
* Find a blueprint by name
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
* @throws \Kirby\Exception\NotFoundException If the blueprint cannot be found
|
||||
*/
|
||||
public static function find(string $name): array
|
||||
@@ -283,8 +263,10 @@ class Blueprint
|
||||
$root = $kirby->root('blueprints');
|
||||
$file = $root . '/' . $name . '.yml';
|
||||
|
||||
// first try to find a site blueprint,
|
||||
// then check in the plugin extensions
|
||||
// first try to find the blueprint in the `site/blueprints` root,
|
||||
// then check in the plugin extensions which includes some default
|
||||
// core blueprints (e.g. page, file, site and block defaults)
|
||||
// as well as blueprints provided by plugins
|
||||
if (F::exists($file, $root) !== true) {
|
||||
$file = $kirby->extension('blueprints', $name);
|
||||
}
|
||||
@@ -311,20 +293,14 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Used to translate any label, heading, etc.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $fallback
|
||||
* @return mixed
|
||||
*/
|
||||
protected function i18n($value, $fallback = null)
|
||||
protected function i18n(mixed $value, mixed $fallback = null): mixed
|
||||
{
|
||||
return I18n::translate($value, $fallback ?? $value);
|
||||
return I18n::translate($value, $fallback) ?? $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is the default blueprint
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefault(): bool
|
||||
{
|
||||
@@ -333,44 +309,33 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Loads a blueprint from file or array
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public static function load(string $name): array
|
||||
{
|
||||
$props = static::find($name);
|
||||
|
||||
$normalize = function ($props) use ($name) {
|
||||
// inject the filename as name if no name is set
|
||||
$props['name'] ??= $name;
|
||||
// inject the filename as name if no name is set
|
||||
$props['name'] ??= $name;
|
||||
|
||||
// normalize the title
|
||||
$title = $props['title'] ?? ucfirst($props['name']);
|
||||
// normalize the title
|
||||
$title = $props['title'] ?? ucfirst($props['name']);
|
||||
|
||||
// translate the title
|
||||
$props['title'] = I18n::translate($title, $title);
|
||||
// translate the title
|
||||
$props['title'] = I18n::translate($title) ?? $title;
|
||||
|
||||
return $props;
|
||||
};
|
||||
|
||||
return $normalize($props);
|
||||
return $props;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent model
|
||||
*
|
||||
* @return \Kirby\Cms\Model
|
||||
*/
|
||||
public function model()
|
||||
public function model(): ModelWithContent
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blueprint name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name(): string
|
||||
{
|
||||
@@ -379,10 +344,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Normalizes all required props in a column setup
|
||||
*
|
||||
* @param string $tabName
|
||||
* @param array $columns
|
||||
* @return array
|
||||
*/
|
||||
protected function normalizeColumns(string $tabName, array $columns): array
|
||||
{
|
||||
@@ -415,10 +376,6 @@ class Blueprint
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $items
|
||||
* @return string
|
||||
*/
|
||||
public static function helpList(array $items): string
|
||||
{
|
||||
$md = [];
|
||||
@@ -434,7 +391,6 @@ class Blueprint
|
||||
* Normalize field props for a single field
|
||||
*
|
||||
* @param array|string $props
|
||||
* @return array
|
||||
* @throws \Kirby\Exception\InvalidArgumentException If the filed name is missing or the field type is invalid
|
||||
*/
|
||||
public static function fieldProps($props): array
|
||||
@@ -486,10 +442,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Creates an error field with the given error message
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $message
|
||||
* @return array
|
||||
*/
|
||||
public static function fieldError(string $name, string $message): array
|
||||
{
|
||||
@@ -505,9 +457,6 @@ class Blueprint
|
||||
/**
|
||||
* Normalizes all fields and adds automatic labels,
|
||||
* types and widths.
|
||||
*
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
public static function fieldsProps($fields): array
|
||||
{
|
||||
@@ -568,12 +517,12 @@ class Blueprint
|
||||
* constructor of an extended class, if you want to make use of it.
|
||||
*
|
||||
* @param array|true|false|null|string $options
|
||||
* @param array $defaults
|
||||
* @param array $aliases
|
||||
* @return array
|
||||
*/
|
||||
protected function normalizeOptions($options, array $defaults, array $aliases = []): array
|
||||
{
|
||||
protected function normalizeOptions(
|
||||
$options,
|
||||
array $defaults,
|
||||
array $aliases = []
|
||||
): array {
|
||||
// return defaults when options are not defined or set to true
|
||||
if ($options === true) {
|
||||
return $defaults;
|
||||
@@ -601,13 +550,11 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Normalizes all required keys in sections
|
||||
*
|
||||
* @param string $tabName
|
||||
* @param array $sections
|
||||
* @return array
|
||||
*/
|
||||
protected function normalizeSections(string $tabName, array $sections): array
|
||||
{
|
||||
protected function normalizeSections(
|
||||
string $tabName,
|
||||
array $sections
|
||||
): array {
|
||||
foreach ($sections as $sectionName => $sectionProps) {
|
||||
// unset / remove section if its property is false
|
||||
if ($sectionProps === false) {
|
||||
@@ -683,9 +630,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Normalizes all required keys in tabs
|
||||
*
|
||||
* @param array $tabs
|
||||
* @return array
|
||||
*/
|
||||
protected function normalizeTabs($tabs): array
|
||||
{
|
||||
@@ -723,9 +667,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Injects a blueprint preset
|
||||
*
|
||||
* @param array $props
|
||||
* @return array
|
||||
*/
|
||||
protected function preset(array $props): array
|
||||
{
|
||||
@@ -748,11 +689,8 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Returns a single section by name
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Kirby\Cms\Section|null
|
||||
*/
|
||||
public function section(string $name)
|
||||
public function section(string $name): Section|null
|
||||
{
|
||||
if (empty($this->sections[$name]) === true) {
|
||||
return null;
|
||||
@@ -770,8 +708,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Returns all sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sections(): array
|
||||
{
|
||||
@@ -783,9 +719,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Returns a single tab by name
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return array|null
|
||||
*/
|
||||
public function tab(string|null $name = null): array|null
|
||||
{
|
||||
@@ -798,8 +731,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Returns all tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tabs(): array
|
||||
{
|
||||
@@ -808,8 +739,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Returns the blueprint title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
@@ -818,8 +747,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Converts the blueprint object to a plain array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
|
Reference in New Issue
Block a user