3 namespace Drupal\paragraphs_test\Plugin\paragraphs\Behavior;
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;
13 * Provides a test feature plugin.
15 * @ParagraphsBehavior(
16 * id = "test_bold_text",
17 * label = @Translation("Test bold text plugin"),
18 * description = @Translation("Test bold text plugin"),
22 class TestBoldTextBehavior extends ParagraphsBehaviorBase {
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."),
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';
50 public static function isApplicable(ParagraphsType $paragraphs_type) {
51 // If the name of the field is not text_paragraph_test then allow using this
53 if ($paragraphs_type->id() != 'text_paragraph_test') {
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')];