Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / tests / modules / paragraphs_test / src / Plugin / paragraphs / Behavior / TestTextColorBehavior.php
1 <?php
2
3 namespace Drupal\paragraphs_test\Plugin\paragraphs\Behavior;
4
5 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\paragraphs\Entity\Paragraph;
8 use Drupal\paragraphs\ParagraphInterface;
9 use Drupal\paragraphs\ParagraphsBehaviorBase;
10
11 /**
12  * Provides a test feature plugin.
13  *
14  * @ParagraphsBehavior(
15  *   id = "test_text_color",
16  *   label = @Translation("Test text color behavior plugin"),
17  *   description = @Translation("Test text color behavior plugin"),
18  *   weight = 1
19  * )
20  */
21 class TestTextColorBehavior extends ParagraphsBehaviorBase {
22
23   /**
24    * {@inheritdoc}
25    */
26   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
27     $form['default_color'] = [
28       '#type' => 'textfield',
29       '#title' => $this->t('Default Color'),
30       '#maxlength' => 255,
31       '#default_value' => $this->configuration['default_color'],
32       '#description' => $this->t("Text color for the paragraph."),
33     ];
34     return $form;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
41     if ($form_state->getValue('default_color') == 'red') {
42       $form_state->setErrorByName('default_color', $this->t('Red can not be used as the default color.'));
43     }
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
50     $this->configuration['default_color'] = $form_state->getValue('default_color');
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function defaultConfiguration() {
57     return [
58       'default_color' => 'blue',
59     ];
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
66     $form['text_color'] = [
67       '#type' => 'textfield',
68       '#title' => $this->t('Color'),
69       '#maxlength' => 255,
70       '#default_value' => $paragraph->getBehaviorSetting($this->getPluginId(), 'text_color', $this->configuration['default_color']),
71       '#description' => $this->t("Text color for the paragraph."),
72     ];
73     return $form;
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function validateBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
80     if ($form_state->getValue('text_color') != 'blue' && $form_state->getValue('text_color') != 'red') {
81       $form_state->setError($form, 'The only allowed values are blue and red.');
82     }
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function view(array &$build, Paragraph $paragraphs_entity, EntityViewDisplayInterface $display, $view_mode) {
89     if ($color = $paragraphs_entity->getBehaviorSetting($this->getPluginId(), 'text_color')) {
90       $build['#attributes']['class'][] = $color . '_plugin_text';
91       $build['#attached']['library'][] = 'paragraphs_test/drupal.paragraphs_test.color_text';
92     }
93   }
94
95   /**
96    * {@inheritdoc}
97    */
98   public function settingsSummary(Paragraph $paragraph) {
99     $text_color = $paragraph->getBehaviorSetting($this->pluginId, 'text_color');
100     return [$this->t('Text color: @color', ['@color' => $text_color])];
101   }
102 }