Using form element in custom form

Created on 29 March 2024, 8 months ago

Problem/Motivation

How would I be able to use this in code with an entity reference view as the selection settings. I currently have the following that works to select all profile nodes :

    $form['profile'] = [
      '#type' => 'selectize_entity_autocomplete',
      '#target_type' => 'node',
      '#title' => $this->t('Profile'),
      '#title_display' => 'none',
      '#settings' => [
        'maxItems' => 1,
        'delimiter' => ', ',
        'closeAfterSelect' => true,
        'plugins' => ['remove_button'],
      ],
      '#selection_settings' => [
        'target_bundles' => ['profile']
      ],
      '#required' => TRUE,
    ];

I want to be able to use an entity reference view instead of getting all profile nodes. I tried this but it doesnt work :

    $form['profile'] = [
      '#type' => 'selectize_entity_autocomplete',
      '#target_type' => 'node',
      '#title' => $this->t('Profile'),
      '#title_display' => 'none',
      '#settings' => [
        'maxItems' => 1,
        'delimiter' => ', ',
        'closeAfterSelect' => true,
        'plugins' => ['remove_button'],
      ],
      '#selection_settings' => [
        'view' => [
          'view_name' => 'profile_reference',
          'display_name' => 'enity_reference_profiles',
          'arguments' => []
        ],
        'match_operator' => 'CONTAINS'
      ],
      '#required' => TRUE,
    ];

Any help would be much appreciated.

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom mistergroove

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024