improvements-2.x-dev/modules/improvements_paragraphs/src/Plugin/paragraphs/Behavior/PublicationStatusParagraphBehavior.php
modules/improvements_paragraphs/src/Plugin/paragraphs/Behavior/PublicationStatusParagraphBehavior.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 = "publication_status", * label = @Translation("Publication status"), * description = @Translation("Allows to set paragraph publication status."), * weight = 1001, * ) */ class PublicationStatusParagraphBehavior extends ParagraphsBehaviorBase { /** * {@inheritdoc} */ public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state): array { $form['status'] = [ '#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $paragraph->isPublished(), ]; $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('status', !empty($filtered_values['status'])); } /** * {@inheritdoc} */ public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode) { // } }