Answers for "provide filter condition in autocomplet field in drupal form using property"

PHP
0

provide filter condition in autocomplet field in drupal form using property

<?php

namespace Drupal\test_module_name\Plugin\EntityReferenceSelection;

use Drupal\node\Plugin\EntityReferenceSelection\NodeSelection;

/**
 * Provides specific access control for the node entity type.
 *
 * @EntityReferenceSelection(
 *   id = "default:node_by_field",
 *   label = @Translation("Node by field selection"),
 *   entity_types = {"node"},
 *   group = "default",
 *   weight = 3
 * )
 */
class NodeByFieldSelection extends NodeSelection {

  /**
   * {@inheritdoc}
   */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match, $match_operator);
    $handler_settings = $this->configuration['handler_settings'];
    if (!isset($handler_settings['filter'])) {
      return $query;
    }
    $filter_settings = $handler_settings['filter'];
    foreach ($filter_settings as $field_name => $value) {
      $query->condition($field_name, $value, '=');
    }
    return $query;
  }

}
Posted by: Guest on July-22-2020
0

provide filter condition in autocomplet field in drupal form using property

$form['my_element'] = [
  '#type' => 'entity_autocomplete',
  '#target_type' => 'node',
  '#selection_handler' => 'default:node_by_field',
  '#selection_settings' => [
    'target_bundles' => ['article'],
    'filter' => ['field_dummy_filter' => $dummy_field_value],
  ],
];
Posted by: Guest on July-22-2020

Code answers related to "provide filter condition in autocomplet field in drupal form using property"

Browse Popular Code Answers by Language