Account created on 2 December 2020, over 4 years ago
#

Recent comments

🇫🇷France allan.ordogh

Thank you for your reply ! Yes I checked the module yesterday and I found the same answer :/

🇫🇷France allan.ordogh

Same problem, my Selection doesn't appear in the Reference method list in the UI with the code :

namespace Drupal\my_module\Plugin\EntityReferenceSelection;

use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\Core\Entity\Query\QueryInterface;

/**
 * Provides entity reference selections to list only the field of the "product" bundle.
 *
 * @EntityReferenceSelection(
 *   id = "custom:my_id",
 *   label = @Translation("My label"),
 *   base_plugin_label = @Translation("My label"),
 *   group = "custom",
 *   weight = 2
 * )
 */
class MyClasseSelection extends DefaultSelection {

   /**
   * {@inheritdoc}
   */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS'): QueryInterface {

    $query = parent::buildEntityQuery($match, $match_operator);
    $query->condition('bundle', 'product');

    return $query;
  }

}

It's interpreted well when i put it in the config file :

settings:
  handler: 'custom:my_id'
  handler_settings:
    target_bundles: null
    sort:
      field: weight
      direction: ASC
    auto_create: false

Context : I want to use an entity reference field on my fields but i can't target the bundle in the UI.

Production build 0.71.5 2024