public function InlineParagraphsWidget::settingsForm

File

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 97

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = array();
  $elements['title'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Paragraph Title'),
    '#description' => $this
      ->t('Label to appear as title on the button as "Add new [title]", this label is translatable'),
    '#default_value' => $this
      ->getSetting('title'),
    '#required' => TRUE,
  );
  $elements['title_plural'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Plural Paragraph Title'),
    '#description' => $this
      ->t('Title in its plural form.'),
    '#default_value' => $this
      ->getSetting('title_plural'),
    '#required' => TRUE,
  );
  $elements['edit_mode'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Edit mode'),
    '#description' => $this
      ->t('The mode the paragraph is in by default. Preview will render the paragraph in the preview view mode.'),
    '#options' => array(
      'open' => $this
        ->t('Open'),
      'closed' => $this
        ->t('Closed'),
      'preview' => $this
        ->t('Preview'),
    ),
    '#default_value' => $this
      ->getSetting('edit_mode'),
    '#required' => TRUE,
  );
  $elements['add_mode'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Add mode'),
    '#description' => $this
      ->t('The way to add new Paragraphs.'),
    '#options' => array(
      'select' => $this
        ->t('Select list'),
      'button' => $this
        ->t('Buttons'),
      'dropdown' => $this
        ->t('Dropdown button'),
    ),
    '#default_value' => $this
      ->getSetting('add_mode'),
    '#required' => TRUE,
  );
  $elements['form_display_mode'] = array(
    '#type' => 'select',
    '#options' => \Drupal::service('entity_display.repository')
      ->getFormModeOptions($this
      ->getFieldSetting('target_type')),
    '#description' => $this
      ->t('The form display mode to use when rendering the paragraph form.'),
    '#title' => $this
      ->t('Form display mode'),
    '#default_value' => $this
      ->getSetting('form_display_mode'),
    '#required' => TRUE,
  );
  $options = [];
  foreach ($this
    ->getAllowedTypes() as $key => $bundle) {
    $options[$key] = $bundle['label'];
  }
  $elements['default_paragraph_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default paragraph type'),
    '#empty_value' => '_none',
    '#default_value' => $this
      ->getDefaultParagraphTypeMachineName(),
    '#options' => $options,
    '#description' => $this
      ->t('When creating a new host entity, a paragraph of this type is added.'),
  ];
  return $elements;
}