public function ProductForm::buildForm in Commerce Core 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- modules/
product/ src/ Form/ ProductForm.php, line 62
Class
- ProductForm
- Defines the product add/edit form.
Namespace
Drupal\commerce_product\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Skip building the form if there are no available stores.
$store_query = $this->entityTypeManager
->getStorage('commerce_store')
->getQuery()
->accessCheck(TRUE);
if ($store_query
->count()
->execute() == 0) {
$link = Link::createFromRoute('Add a new store.', 'entity.commerce_store.add_page');
$form['warning'] = [
'#markup' => $this
->t("Products can't be created until a store has been added. @link", [
'@link' => $link
->toString(),
]),
];
return $form;
}
return parent::buildForm($form, $form_state);
}