3 namespace Drupal\paragraphs_test\Plugin\paragraphs\Behavior;
4 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\paragraphs\Entity\Paragraph;
7 use Drupal\paragraphs\ParagraphsBehaviorBase;
10 * Test plugin with field selection.
12 * @ParagraphsBehavior(
13 * id = "test_field_selection",
14 * label = @Translation("Test field selection for behavior plugin"),
15 * description = @Translation("Test field selection for behavior plugin"),
19 class TestFieldsSelectionBehavior extends ParagraphsBehaviorBase {
24 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
25 $form['field_selection_filter'] = [
27 '#options' => $this->getFieldNameOptions($form_state->getFormObject()->getEntity(), 'image'),
28 '#title' => $this->t('Paragraph fields'),
29 '#default_value' => $this->configuration['field_selection_filter'],
30 '#description' => $this->t("Choose filtered paragraph field to be applied."),
33 $form['field_selection'] = [
35 '#options' => $this->getFieldNameOptions($form_state->getFormObject()->getEntity()),
36 '#title' => $this->t('Paragraph fields'),
37 '#default_value' => $this->configuration['field_selection'],
38 '#description' => $this->t("Choose paragraph field to be applied."),
46 public function defaultConfiguration() {
48 'field_selection' => '',
49 'field_selection_filter' => '',
56 public function view(array &$build, Paragraph $paragraphs_entity, EntityViewDisplayInterface $display, $view_mode) {}