7

How can users add products to a simple plugin config using an autocomplete field?

I tried to use Config Entity but it looks the same as Form API (and I can't use entity fields there).

Chris Happy
  • 7,088
  • 2
  • 22
  • 49

2 Answers2

14

I was able to do this in Drupal 8 using the form API and the entity_autocomplete type.

$form['stories'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'node',
    '#title' => $this->t('Stories'),
    '#description' => $this->t('Select some stories.'),
    '#default_value' => $default_entities,
    '#tags' => TRUE,
    '#selection_settings' => array(
        'target_bundles' => array('page', 'article'),
    ),
    '#weight' => '0',
];
nrackleff
  • 166
  • 6
-1

Use webform - there is an entity reference field. This won't be useable for your purpose .. but you can check the source for sake.

rémy
  • 1,026
  • 13
  • 18