@@ -55,6 +55,9 @@ class SearchEditor extends Form
5555 /** @var bool */
5656 protected $ cleared = false ;
5757
58+ /** @var string[] Additional `metadata` fields for the condition */
59+ protected array $ metadataFields = [];
60+
5861 /**
5962 * Set the filter query string to populate the form with
6063 *
@@ -95,6 +98,22 @@ public function setSuggestionUrl(Url $url)
9598 return $ this ;
9699 }
97100
101+ /**
102+ * Set additional `metadata` fields for the condition
103+ *
104+ * The value of these fields is populated to condition's `metadata`
105+ *
106+ * @param array $fields
107+ *
108+ * @return $this
109+ */
110+ public function setMetadataFields (array $ fields ): static
111+ {
112+ $ this ->metadataFields = $ fields ;
113+
114+ return $ this ;
115+ }
116+
98117 /**
99118 * Get the query string parser being used
100119 *
@@ -551,6 +570,19 @@ protected function createCondition(Filter\Condition $condition, $identifier)
551570 }]
552571 ]);
553572
573+ $ metadataFields = new HtmlDocument ();
574+ foreach ($ this ->metadataFields as $ fieldNameSuffix ) {
575+ $ name = $ identifier . '-column-metadata- ' . $ fieldNameSuffix ;
576+ $ columnMetaInput = $ this ->createElement ('hidden ' , $ name , [
577+ 'value ' => $ condition ->metaData ()->get ($ fieldNameSuffix )
578+ ]);
579+ $ this ->registerElement ($ columnMetaInput );
580+
581+ $ condition ->metaData ()->set ($ fieldNameSuffix , $ this ->getValue ($ name ));
582+
583+ $ metadataFields ->addHtml ($ columnMetaInput );
584+ }
585+
554586 $ operatorInput = $ this ->createElement ('select ' , $ identifier . '-operator ' , [
555587 'options ' => [
556588 '~ ' => '~ ' ,
@@ -588,6 +620,7 @@ protected function createCondition(Filter\Condition $condition, $identifier)
588620 $ columnInput ,
589621 $ columnFakeInput ,
590622 $ columnSearchInput ,
623+ $ metadataFields ,
591624 $ operatorInput ,
592625 $ valueInput
593626 );
0 commit comments