mirror of
https://github.com/getgrav/grav.git
synced 2026-07-08 18:01:45 +02:00
Define FormInterface
This commit is contained in:
@@ -325,10 +325,7 @@ class FlexForm implements FlexFormInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function reset(): FlexFormInterface
|
||||
public function reset(): void
|
||||
{
|
||||
$this->data = null;
|
||||
$this->files = [];
|
||||
@@ -339,8 +336,6 @@ class FlexForm implements FlexFormInterface
|
||||
$flash = $this->getFlash();
|
||||
$flash->delete();
|
||||
$this->flash = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
|
||||
namespace Grav\Framework\Flex\Interfaces;
|
||||
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Framework\Form\Interfaces\FormInterface;
|
||||
use Grav\Framework\Route\Route;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
@@ -19,81 +18,8 @@ use Psr\Http\Message\UploadedFileInterface;
|
||||
* Class FlexForm
|
||||
* @package Grav\Framework\Flex
|
||||
*/
|
||||
interface FlexFormInterface extends \Serializable
|
||||
interface FlexFormInterface extends \Serializable, FormInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string;
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*/
|
||||
public function setId(string $id): void;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUniqueId(): string;
|
||||
|
||||
/**
|
||||
* @param string $uniqueId
|
||||
*/
|
||||
public function setUniqueId(string $uniqueId): void;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceName(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceAction(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAction(): string;
|
||||
|
||||
/**
|
||||
* @return Data|FlexObjectInterface
|
||||
*/
|
||||
public function getData();
|
||||
|
||||
/**
|
||||
* Get a value from the form.
|
||||
*
|
||||
* Note: Used in form fields.
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue(string $name);
|
||||
|
||||
/**
|
||||
* @return UploadedFileInterface[]
|
||||
*/
|
||||
public function getFiles() : array;
|
||||
|
||||
/**
|
||||
* @return Route|null
|
||||
*/
|
||||
public function getFileUploadAjaxRoute(): ?Route;
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $filename
|
||||
* @return Route|null
|
||||
*/
|
||||
public function getFileDeleteAjaxRoute($field, $filename): ?Route;
|
||||
|
||||
/**
|
||||
* @return FlexObjectInterface
|
||||
*/
|
||||
@@ -105,6 +31,13 @@ interface FlexFormInterface extends \Serializable
|
||||
*/
|
||||
public function handleRequest(ServerRequestInterface $request): self;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param UploadedFileInterface[] $files
|
||||
* @return $this
|
||||
*/
|
||||
public function submit(array $data, array $files = null): self;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -120,30 +53,6 @@ interface FlexFormInterface extends \Serializable
|
||||
*/
|
||||
public function isSubmitted(): bool;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param UploadedFileInterface[] $files
|
||||
* @return $this
|
||||
*/
|
||||
public function submit(array $data, array $files = null): self;
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function reset(): self;
|
||||
|
||||
/**
|
||||
* Note: Used in form fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFields(): array;
|
||||
|
||||
/**
|
||||
* @return Blueprint
|
||||
*/
|
||||
public function getBlueprint(): Blueprint;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -153,4 +62,16 @@ interface FlexFormInterface extends \Serializable
|
||||
* @return string
|
||||
*/
|
||||
public function getMediaRoute(): string;
|
||||
|
||||
/**
|
||||
* @return Route|null
|
||||
*/
|
||||
public function getFileUploadAjaxRoute(): ?Route;
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $filename
|
||||
* @return Route|null
|
||||
*/
|
||||
public function getFileDeleteAjaxRoute($field, $filename): ?Route;
|
||||
}
|
||||
|
||||
129
system/src/Grav/Framework/Form/Interfaces/FormInterface.php
Normal file
129
system/src/Grav/Framework/Form/Interfaces/FormInterface.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Framework\Form
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Framework\Form\Interfaces;
|
||||
|
||||
use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\Data\Data;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
/**
|
||||
* Interface FormInterface
|
||||
* @package Grav\Framework\Form
|
||||
*/
|
||||
interface FormInterface
|
||||
{
|
||||
/**
|
||||
* Get HTML id="..." attribute.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string;
|
||||
|
||||
/**
|
||||
* Sets HTML id="" attribute.
|
||||
*
|
||||
* @param string $id
|
||||
*/
|
||||
public function setId(string $id): void;
|
||||
|
||||
/**
|
||||
* Get unique id for the current form instance. By default regenerated on every page reload.
|
||||
*
|
||||
* This id is used to load the saved form state, if available.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUniqueId(): string;
|
||||
|
||||
/**
|
||||
* Sets unique form id.
|
||||
*
|
||||
* @param string $uniqueId
|
||||
*/
|
||||
public function setUniqueId(string $uniqueId): void;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* Get form name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormName(): string;
|
||||
|
||||
/**
|
||||
* Get nonce name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceName(): string;
|
||||
|
||||
/**
|
||||
* Get nonce action.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNonceAction(): string;
|
||||
|
||||
/**
|
||||
* Get form action (URL). If action is empty, it points to the current page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAction(): string;
|
||||
|
||||
/**
|
||||
* Get current data passed to the form.
|
||||
*
|
||||
* @return Data|object
|
||||
*/
|
||||
public function getData();
|
||||
|
||||
/**
|
||||
* Get files which were passed to the form.
|
||||
*
|
||||
* @return array|UploadedFileInterface[]
|
||||
*/
|
||||
public function getFiles(): array;
|
||||
|
||||
/**
|
||||
* Get a value from the form.
|
||||
*
|
||||
* Note: Used in form fields.
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue(string $name);
|
||||
|
||||
/**
|
||||
* Reset form.
|
||||
*/
|
||||
public function reset(): void;
|
||||
|
||||
/**
|
||||
* Get form fields as an array.
|
||||
*
|
||||
* Note: Used in form fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFields(): array;
|
||||
|
||||
/**
|
||||
* Get blueprint used in the form.
|
||||
*
|
||||
* @return Blueprint
|
||||
*/
|
||||
public function getBlueprint(): Blueprint;
|
||||
}
|
||||
Reference in New Issue
Block a user