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 / TestBoldTextBehavior.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\Entity\ParagraphsType;
9 use Drupal\paragraphs\ParagraphInterface;
10 use Drupal\paragraphs\ParagraphsBehaviorBase;
11
12 /**
13  * Provides a test feature plugin.
14  *
15  * @ParagraphsBehavior(
16  *   id = "test_bold_text",
17  *   label = @Translation("Test bold text plugin"),
18  *   description = @Translation("Test bold text plugin"),
19  *   weight = 2
20  * )
21  */
22 class TestBoldTextBehavior extends ParagraphsBehaviorBase {
23
24   /**
25    * {@inheritdoc}
26    */
27   public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
28     $form['bold_text'] = [
29       '#type' => 'checkbox',
30       '#title' => $this->t('Bold Text'),
31       '#default_value' => $paragraph->getBehaviorSetting($this->getPluginId(), 'bold_text', FALSE),
32       '#description' => $this->t("Bold text for the paragraph."),
33     ];
34     return $form;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function view(array &$build, Paragraph $paragraphs_entity, EntityViewDisplayInterface $display, $view_mode) {
41     if ($paragraphs_entity->getBehaviorSetting($this->getPluginId(), 'bold_text')) {
42       $build['#attributes']['class'][] = 'bold_plugin_text';
43       $build['#attached']['library'][] = 'paragraphs_test/drupal.paragraphs_test.bold_text';
44     }
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public static function isApplicable(ParagraphsType $paragraphs_type) {
51     // If the name of the field is not text_paragraph_test then allow using this
52     // plugin.
53     if ($paragraphs_type->id() != 'text_paragraph_test') {
54       return TRUE;
55     }
56     return FALSE;
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function settingsSummary(Paragraph $paragraph) {
63     $bold_setting = $paragraph->getBehaviorSetting($this->getPluginId(), 'bold_text');
64     return [$bold_setting ? $this->t('Bold: Yes') : $this->t('Bold: No')];
65   }
66 }