improvements-2.x-dev/modules/improvements_paragraphs/src/Plugin/paragraphs/Behavior/LabelParagraphBehavior.php

modules/improvements_paragraphs/src/Plugin/paragraphs/Behavior/LabelParagraphBehavior.php
<?php

namespace Drupal\improvements_paragraphs\Plugin\paragraphs\Behavior;

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\paragraphs\ParagraphsBehaviorBase;

/**
 * @ParagraphsBehavior(
 *   id = "label",
 *   label = @Translation("Label"),
 *   description = @Translation("Allows to set paragraph label."),
 *   weight = 101,
 * )
 */
class LabelParagraphBehavior extends ParagraphsBehaviorBase {

  /**
   * {@inheritdoc}
   */
  public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state): array {
    $form['label'] = [
      '#type' => 'textfield',
      '#title' => t('Label'),
      '#default_value' => $paragraph->get('label')->value,
    ];

    $form['#weight'] = $this->pluginDefinition['weight'];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state): void {
    $filtered_values = $this->filterBehaviorFormSubmitValues($paragraph, $form, $form_state);
    $paragraph->set('label', $filtered_values['label'] ?? NULL);
  }

  /**
   * {@inheritdoc}
   */
  public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode) {
    //
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc