Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / plugin / entity-reference-selection.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/entity-reference-selection.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/entity-reference-selection.twig
new file mode 100644 (file)
index 0000000..296fba0
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Plugin\EntityReferenceSelection;
+
+{% sort %}
+{% if configurable %}
+use Drupal\Core\Form\FormStateInterface;
+{% endif %}
+use {{ base_class_full }};
+{% endsort %}
+
+/**
+ * Plugin description.
+ *
+ * @EntityReferenceSelection(
+ *   id = "{{ plugin_id }}",
+ *   label = @Translation("{{ plugin_label }}"),
+ *   group = "{{ plugin_id }}",
+ *   entity_types = {"{{ entity_type }}"},
+ *   weight = 0
+ * )
+ */
+class {{ class }} extends {{ base_class }} {
+
+{% if configurable %}
+  /**
+   * {@inheritdoc}
+   */
+  public function defaultConfiguration() {
+
+    $default_configuration = [
+      'foo' => 'bar',
+    ];
+
+    return $default_configuration + parent::defaultConfiguration();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
+    $form = parent::buildConfigurationForm($form, $form_state);
+
+    $form['foo'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Foo'),
+      '#default_value' => $this->configuration['foo'],
+    ];
+
+    return $form;
+  }
+
+{% endif %}
+  /**
+   * {@inheritdoc}
+   */
+  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
+    $query = parent::buildEntityQuery($match, $match_operator);
+
+    // @DCG
+    // Here you can apply addition conditions, sorting, etc to the query.
+    // Also see self::entityQueryAlter().
+    $query->condition('field_example', 123);
+
+    return $query;
+  }
+
+}