Add blueprints and fake content

This commit is contained in:
Paul Nicoué 2021-11-18 17:44:47 +01:00
parent 1ff19bf38f
commit 8235816462
592 changed files with 22385 additions and 31535 deletions

View file

@ -5,8 +5,9 @@ namespace Kirby\Cms;
use Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\F;
use Kirby\Filesystem\Dir;
use Kirby\Filesystem\F;
use Kirby\Panel\User as Panel;
use Kirby\Toolkit\Str;
/**
@ -115,7 +116,7 @@ class User extends ModelWithContent
}
// return site content otherwise
return $this->content()->get($method, $arguments);
return $this->content()->get($method);
}
/**
@ -125,7 +126,8 @@ class User extends ModelWithContent
*/
public function __construct(array $props)
{
$props['id'] = $props['id'] ?? $this->createId();
// TODO: refactor later to avoid redundant prop setting
$this->setProperty('id', $props['id'] ?? $this->createId(), true);
$this->setProperties($props);
}
@ -578,92 +580,13 @@ class User extends ModelWithContent
}
/**
* Panel icon definition
* Returns the panel info object
*
* @internal
* @param array $params
* @return array
* @return \Kirby\Panel\User
*/
public function panelIcon(array $params = null): array
public function panel()
{
$params['type'] = 'user';
return parent::panelIcon($params);
}
/**
* Returns the image file object based on provided query
*
* @internal
* @param string|null $query
* @return \Kirby\Cms\File|\Kirby\Cms\Asset|null
*/
protected function panelImageSource(string $query = null)
{
if ($query === null) {
return $this->avatar();
}
return parent::panelImageSource($query);
}
/**
* Returns the full path without leading slash
*
* @internal
* @return string
*/
public function panelPath(): string
{
return 'users/' . $this->id();
}
/**
* Returns prepared data for the panel user picker
*
* @param array|null $params
* @return array
*/
public function panelPickerData(array $params = null): array
{
$image = $this->panelImage($params['image'] ?? []);
$icon = $this->panelIcon($image);
// escape the default text
// TODO: no longer needed in 3.6
$textQuery = $params['text'] ?? '{{ user.username }}';
$text = $this->toString($textQuery);
if ($textQuery === '{{ user.username }}') {
$text = Escape::html($text);
}
return [
'icon' => $icon,
'id' => $this->id(),
'image' => $image,
'email' => $this->email(),
'info' => $this->toString($params['info'] ?? false),
'link' => $this->panelUrl(true),
'text' => $text,
'username' => $this->username(),
];
}
/**
* Returns the url to the editing view
* in the panel
*
* @internal
* @param bool $relative
* @return string
*/
public function panelUrl(bool $relative = false): string
{
if ($relative === true) {
return '/' . $this->panelPath();
} else {
return $this->kirby()->url('panel') . '/' . $this->panelPath();
}
return new Panel($this);
}
/**
@ -909,13 +832,13 @@ class User extends ModelWithContent
* @param string $fallback Fallback for tokens in the template that cannot be replaced
* @return string
*/
public function toString(string $template = null, array $data = [], string $fallback = ''): string
public function toString(string $template = null, array $data = [], string $fallback = '', string $handler = 'template'): string
{
if ($template === null) {
$template = $this->email();
}
return parent::toString($template, $data);
return parent::toString($template, $data, $fallback, $handler);
}
/**
@ -951,9 +874,61 @@ class User extends ModelWithContent
}
if (password_verify($password, $this->password()) !== true) {
throw new InvalidArgumentException(['key' => 'user.password.wrong']);
throw new InvalidArgumentException(['key' => 'user.password.wrong', 'httpCode' => 401]);
}
return true;
}
/**
* Deprecated!
*/
/**
* Returns the full path without leading slash
*
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @internal
* @return string
* @codeCoverageIgnore
*/
public function panelPath(): string
{
return $this->panel()->path();
}
/**
* Returns prepared data for the panel user picker
*
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @param array|null $params
* @return array
* @codeCoverageIgnore
*/
public function panelPickerData(array $params = null): array
{
return $this->panel()->pickerData($params);
}
/**
* Returns the url to the editing view
* in the panel
*
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @internal
* @param bool $relative
* @return string
* @codeCoverageIgnore
*/
public function panelUrl(bool $relative = false): string
{
return $this->panel()->url($relative);
}
}