You are here

public function ShippingMethodForm::buildForm in Commerce Shipping 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

src/Form/ShippingMethodForm.php, line 14

Class

ShippingMethodForm

Namespace

Drupal\commerce_shipping\Form

Code

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(FALSE);
  if ($store_query
    ->count()
    ->execute() == 0) {
    $link = Link::createFromRoute('Add a new store.', 'entity.commerce_store.add_page');
    $form['warning'] = [
      '#markup' => t("Shipping methods can't be created until a store has been added. @link", [
        '@link' => $link
          ->toString(),
      ]),
    ];
    return $form;
  }
  return parent::buildForm($form, $form_state);
}