I am creating a custom form using the form api. I'd like to reuse the price field used by commerce, but I don't know how to include their form type in my own form.
-
possible duplicate of Price field with Currency outside of commerce and ubercart– bethCommented Aug 26, 2014 at 19:43
-
1The question link in my opinion does not show me how to add it to a form using the form api.– BobbyCommented Aug 26, 2014 at 19:52
-
1There's no "currency" or "price" or "money" fieldtype in the form API in core.– bethCommented Aug 26, 2014 at 19:54
-
I do have Drupal Commerce installed all ready. Is it simple to add the price field from that module to my form?– BobbyCommented Aug 26, 2014 at 20:01
-
Yes I think it is just like any other field, but 'type' would be the type defined by Commerce Price instead of a core type. If you look at the code of the field in the Commerce module it should be the same as that.– bethCommented Aug 26, 2014 at 20:08
|
Show 3 more comments
1 Answer
this works for me
$form['price'] = array(
'#type' => 'commerce_price',
'#title' => $this->t('Price'),
);