You are here

public function ProductCategoryTrait::buildConfigurationForm in Commerce Core 8.2

File

modules/product/src/Plugin/Commerce/Condition/ProductCategoryTrait.php, line 46

Class

ProductCategoryTrait
Provides common configuration for the product category conditions.

Namespace

Drupal\commerce_product\Plugin\Commerce\Condition

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $terms = NULL;
  $ids = $this
    ->getTermIds();
  if (!empty($ids)) {
    $term_storage = $this->entityTypeManager
      ->getStorage('taxonomy_term');
    $terms = $term_storage
      ->loadMultiple($ids);
  }
  $form['terms'] = [
    '#type' => 'entity_autocomplete',
    '#title' => $this
      ->t('Categories'),
    '#default_value' => $terms,
    '#target_type' => 'taxonomy_term',
    '#selection_settings' => [
      'target_bundles' => $this
        ->getVocabularyIds(),
    ],
    '#tags' => TRUE,
    '#required' => TRUE,
    '#maxlength' => NULL,
  ];
  return $form;
}