|
|
@@ -136,25 +136,56 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Set the schema for this form.
|
|
|
+ *
|
|
|
+ * @since 4.1.0
|
|
|
+ * @param \Cake\Form\Schema $schema The schema to set
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setSchema(Schema $schema)
|
|
|
+ {
|
|
|
+ $this->_schema = $schema;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get the schema for this form.
|
|
|
+ *
|
|
|
+ * This method will call `_buildSchema()` when the schema
|
|
|
+ * is first built. This hook method lets you configure the
|
|
|
+ * schema or load a pre-defined one.
|
|
|
+ *
|
|
|
+ * @since 4.1.0
|
|
|
+ * @return \Cake\Form\Schema the schema instance.
|
|
|
+ */
|
|
|
+ public function getSchema(): Schema
|
|
|
+ {
|
|
|
+ if ($this->_schema === null) {
|
|
|
+ $this->_schema = $this->_buildSchema(new $this->_schemaClass());
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->_schema;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Get/Set the schema for this form.
|
|
|
*
|
|
|
* This method will call `_buildSchema()` when the schema
|
|
|
* is first built. This hook method lets you configure the
|
|
|
* schema or load a pre-defined one.
|
|
|
*
|
|
|
+ * @deprecated 4.1.0 Use setSchema()/getSchema() instead.
|
|
|
* @param \Cake\Form\Schema|null $schema The schema to set, or null.
|
|
|
* @return \Cake\Form\Schema the schema instance.
|
|
|
*/
|
|
|
public function schema(?Schema $schema = null): Schema
|
|
|
{
|
|
|
- if ($schema === null && empty($this->_schema)) {
|
|
|
- $schema = $this->_buildSchema(new $this->_schemaClass());
|
|
|
- }
|
|
|
- if ($schema) {
|
|
|
- $this->_schema = $schema;
|
|
|
+ if ($schema !== null) {
|
|
|
+ $this->setSchema($schema);
|
|
|
}
|
|
|
|
|
|
- return $this->_schema;
|
|
|
+ return $this->getSchema();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -291,7 +322,7 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
public function __debugInfo(): array
|
|
|
{
|
|
|
$special = [
|
|
|
- '_schema' => $this->schema()->__debugInfo(),
|
|
|
+ '_schema' => $this->getSchema()->__debugInfo(),
|
|
|
'_errors' => $this->getErrors(),
|
|
|
'_validator' => $this->getValidator()->__debugInfo(),
|
|
|
];
|