You are here

public function ParagraphsViewmodeBehavior::buildBehaviorForm in Paragraphs View Modes 8

Builds a behavior perspective for each paragraph based on its type.

This method is responsible for building the behavior form for each Paragraph so the user can set special attributes and properties.

Parameters

\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph.

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The fields build array that the plugin creates.

Overrides ParagraphsBehaviorBase::buildBehaviorForm

File

src/Plugin/paragraphs/Behavior/ParagraphsViewmodeBehavior.php, line 146

Class

ParagraphsViewmodeBehavior
Class ParagraphsViewmodeBehavior.

Namespace

Drupal\paragraphs_viewmode\Plugin\paragraphs\Behavior

Code

public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
  $all_modes = $this->entityDisplayRepository
    ->getViewModeOptions('paragraph');
  $available_modes = array_filter($this->configuration['override_available']);
  $mode = $paragraph
    ->getBehaviorSetting($this->pluginId, 'view_mode', $this->configuration['override_default']);
  $mode_options = array_intersect_key($all_modes, $available_modes);
  $form['view_mode'] = [
    '#type' => 'select',
    '#title' => 'Select which view mode to use for this paragraph',
    '#options' => $mode_options,
    '#default_value' => $mode,
  ];
  return parent::buildBehaviorForm($paragraph, $form, $form_state);
}