You are here

protected function ParagraphsWidget::getSettingOptions in Paragraphs 8

Returns select options for a plugin setting.

This is done to allow \Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget::settingsSummary() to access option labels. Not all plugin setting are available.

Parameters

string $setting_name: The name of the widget setting. Supported settings:

  • "edit_mode"
  • "closed_mode"
  • "autocollapse"
  • "add_mode"

Return value

array|null An array of setting option usable as a value for a "#options" key.

2 calls to ParagraphsWidget::getSettingOptions()
ParagraphsWidget::settingsForm in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Returns a form to configure settings for the widget.
ParagraphsWidget::settingsSummary in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Returns a short summary for the current widget settings.

File

src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 266

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function getSettingOptions($setting_name) {
  switch ($setting_name) {
    case 'edit_mode':
      $options = [
        'open' => $this
          ->t('Open'),
        'closed' => $this
          ->t('Closed'),
        'closed_expand_nested' => $this
          ->t('Closed, show nested'),
      ];
      break;
    case 'closed_mode':
      $options = [
        'summary' => $this
          ->t('Summary'),
        'preview' => $this
          ->t('Preview'),
      ];
      break;
    case 'autocollapse':
      $options = [
        'none' => $this
          ->t('None'),
        'all' => $this
          ->t('All'),
      ];
      break;
    case 'add_mode':
      $options = [
        'select' => $this
          ->t('Select list'),
        'button' => $this
          ->t('Buttons'),
        'dropdown' => $this
          ->t('Dropdown button'),
        'modal' => $this
          ->t('Modal form'),
      ];
      break;
    case 'features':
      $options = [
        'duplicate' => $this
          ->t('Duplicate'),
        'collapse_edit_all' => $this
          ->t('Collapse / Edit all'),
        // The "Add above" feature will be completely injected clientside,
        // whenever this option is enabled in the widget configuration.
        // @see Drupal.behaviors.paragraphsAddAboveButton
        'add_above' => $this
          ->t('Add above'),
      ];
      break;
  }
  return isset($options) ? $options : NULL;
}