diff options
author | Func <Funcer@outlook.com> | 2022-01-20 03:51:31 +0000 |
---|---|---|
committer | Func <Funcer@outlook.com> | 2022-01-31 16:19:44 +0000 |
commit | bf6a65437976b624c381964ca6bb588da6b63edf (patch) | |
tree | a1e30091cf82d5749b3f6798b378cf8909b744aa /includes/htmlform/fields/HTMLFormFieldCloner.php | |
parent | 1dfed9b6d341526d74cfef8012aef0d931206a2a (diff) | |
download | mediawikicore-bf6a65437976b624c381964ca6bb588da6b63edf.tar.gz mediawikicore-bf6a65437976b624c381964ca6bb588da6b63edf.zip |
HTMLFormFieldCloner: Cache form fields for further use
Follow-up changes will use fields more frequently, cache them would be better.
Change-Id: I99dd488a684937b01713663e63d5c3ca68772ef0
Diffstat (limited to 'includes/htmlform/fields/HTMLFormFieldCloner.php')
-rw-r--r-- | includes/htmlform/fields/HTMLFormFieldCloner.php | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/includes/htmlform/fields/HTMLFormFieldCloner.php b/includes/htmlform/fields/HTMLFormFieldCloner.php index 959846fa4b24..359f24ff277e 100644 --- a/includes/htmlform/fields/HTMLFormFieldCloner.php +++ b/includes/htmlform/fields/HTMLFormFieldCloner.php @@ -46,6 +46,9 @@ class HTMLFormFieldCloner extends HTMLFormField { */ protected $uniqueId; + /* @var HTMLFormField[] */ + protected $mFields = []; + /** * @stable to call * @inheritDoc @@ -82,6 +85,17 @@ class HTMLFormFieldCloner extends HTMLFormField { } /** + * @param string $key Array key under which these fields should be named + * @return HTMLFormField[] + */ + protected function getFieldsForKey( $key ) { + if ( !isset( $this->mFields[$key] ) ) { + $this->mFields[$key] = $this->createFieldsForKey( $key ); + } + return $this->mFields[$key]; + } + + /** * Create the HTMLFormFields that go inside this element, using the * specified key. * @@ -169,7 +183,7 @@ class HTMLFormFieldCloner extends HTMLFormField { // wpEditToken don't fail. $data = $this->rekeyValuesArray( $key, $value ) + $request->getValues(); - $fields = $this->createFieldsForKey( $key ); + $fields = $this->getFieldsForKey( $key ); $subrequest = new DerivativeRequest( $request, $data, $request->wasPosted() ); $row = []; foreach ( $fields as $fieldname => $field ) { @@ -187,7 +201,7 @@ class HTMLFormFieldCloner extends HTMLFormField { if ( isset( $values['create'] ) ) { // Non-JS client clicked the "create" button. - $fields = $this->createFieldsForKey( $this->uniqueId ); + $fields = $this->getFieldsForKey( $this->uniqueId ); $row = []; foreach ( $fields as $fieldname => $field ) { if ( !empty( $field->mParams['nodata'] ) ) { @@ -206,7 +220,7 @@ class HTMLFormFieldCloner extends HTMLFormField { // The default is one entry with all subfields at their defaults. if ( $ret === null ) { - $fields = $this->createFieldsForKey( $this->uniqueId ); + $fields = $this->getFieldsForKey( $this->uniqueId ); $row = []; foreach ( $fields as $fieldname => $field ) { if ( !empty( $field->mParams['nodata'] ) ) { @@ -230,7 +244,7 @@ class HTMLFormFieldCloner extends HTMLFormField { } foreach ( $values as $key => $value ) { - $fields = $this->createFieldsForKey( $key ); + $fields = $this->getFieldsForKey( $key ); foreach ( $fields as $fieldname => $field ) { if ( !array_key_exists( $fieldname, $value ) ) { continue; @@ -264,7 +278,7 @@ class HTMLFormFieldCloner extends HTMLFormField { } foreach ( $values as $key => $value ) { - $fields = $this->createFieldsForKey( $key ); + $fields = $this->getFieldsForKey( $key ); foreach ( $fields as $fieldname => $field ) { if ( !array_key_exists( $fieldname, $value ) ) { continue; @@ -299,7 +313,7 @@ class HTMLFormFieldCloner extends HTMLFormField { $hidden = ''; $hasLabel = false; - $fields = $this->createFieldsForKey( $key ); + $fields = $this->getFieldsForKey( $key ); foreach ( $fields as $fieldname => $field ) { $v = array_key_exists( $fieldname, $values ) ? $values[$fieldname] @@ -428,7 +442,7 @@ class HTMLFormFieldCloner extends HTMLFormField { $html = ''; $hidden = ''; - $fields = $this->createFieldsForKey( $key ); + $fields = $this->getFieldsForKey( $key ); foreach ( $fields as $fieldname => $field ) { $v = array_key_exists( $fieldname, $values ) ? $values[$fieldname] |