You are here

class ParagraphsWidget in Paragraphs Sets 8

Plugin implementation of 'entity_reference_revisions paragraphs sets' widget.

Plugin annotation


@FieldWidget(
  id = "paragraphs_sets",
  label = @Translation("Paragraphs sets EXPERIMENTAL"),
  description = @Translation("An experimental paragraphs inline form widget with sets."),
  field_types = {
    "entity_reference_revisions"
  }
)

Hierarchy

Expanded class hierarchy of ParagraphsWidget

File

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

Namespace

Drupal\paragraphs_sets\Plugin\Field\FieldWidget
View source
class ParagraphsWidget extends ParagraphsParagraphsWidget {

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $elements = parent::settingsForm($form, $form_state);
    $options = [];
    foreach (static::getSets() as $key => $set) {
      $options[$key] = $set['label'];
    }
    $elements['default_paragraph_type']['#title'] = $this
      ->t('Default paragraph set');
    $elements['default_paragraph_type']['#description'] = $this
      ->t('When creating a new host entity, the selected set of paragraphs are added.');
    $elements['default_paragraph_type']['#options'] = $options;
    return $elements;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $summary = parent::settingsSummary();
    if ($this
      ->getDefaultParagraphTypeLabelName() !== NULL) {

      // Find "Default paragraph type" in summary and replace it.
      foreach ($summary as $key => $value) {
        if (strpos($value, 'Default paragraph type') !== 0) {
          continue;
        }
        $summary[$key] = $this
          ->t('Default paragraphs set: @default_paragraph_set', [
          '@default_paragraph_set' => $this
            ->getDefaultParagraphTypeLabelName(),
        ]);
      }
    }
    return $summary;
  }

  /**
   * {@inheritdoc}
   */
  public function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
    $host = $items
      ->getEntity();
    $field_name = $this->fieldDefinition
      ->getName();
    $cardinality = $this->fieldDefinition
      ->getFieldStorageDefinition()
      ->getCardinality();
    $this->fieldParents = $form['#parents'];
    $field_state = static::getWidgetState($this->fieldParents, $field_name, $form_state);
    $user_input =& $form_state
      ->getUserInput();
    $max = $field_state['items_count'];
    $entity_type_manager = \Drupal::entityTypeManager();
    $sets = static::getSets();
    $set = isset($field_state['selected_set']) ? $field_state['selected_set'] : NULL;

    // Consider adding a default paragraph for new host entities.
    if ($max == 0 && $items
      ->getEntity()
      ->isNew() && empty($set)) {
      $set = $this
        ->getDefaultParagraphTypeMachineName();
    }
    if ($set) {
      if (isset($field_state['button_type']) && 'set_selection_button' === $field_state['button_type']) {

        // Clear all items.
        $items
          ->filter(function () {
          return FALSE;
        });

        // Clear field state.
        $field_state['paragraphs'] = [];

        // Clear user input.
        foreach ($user_input[$field_name] as $key => $value) {
          if (!is_numeric($key) || empty($value['subform'])) {
            continue;
          }
          unset($user_input[$field_name][$key]);
        }
        $this->realItemCount = 0;
        $max = 0;
      }
      $target_type = $this
        ->getFieldSetting('target_type');
      $context = [
        'set' => $set,
        'field' => $this->fieldDefinition,
        'form' => $form,
        'form_state' => $form_state,
        'entity' => $host,
      ];
      foreach ($sets[$set]['paragraphs'] as $key => $info) {
        $alter_hooks = [
          'paragraphs_set_data',
          'paragraphs_set_' . $set . '_data',
          'paragraphs_set_' . $set . '_' . $field_name . '_data',
        ];
        $context['key'] = $key;
        $context['paragraphs_bundle'] = $info['type'];
        $data = empty($info['data']) ? [] : $info['data'];
        \Drupal::moduleHandler()
          ->alter($alter_hooks, $data, $context);
        $item_values = [
          'type' => $info['type'],
        ] + $data;
        $max++;
        $paragraphs_entity = $entity_type_manager
          ->getStorage($target_type)
          ->create($item_values);
        $display = EntityFormDisplay::collectRenderDisplay($paragraphs_entity, $this
          ->getSetting('form_display_mode'));
        $field_state['paragraphs'][$max - 1] = [
          'entity' => $paragraphs_entity,
          'display' => $display,
          'mode' => 'edit',
          'original_delta' => $max,
        ];
      }
      $field_state['items_count'] = $max;
      $field_state['selected_set'] = NULL;
    }
    $this->realItemCount = $max;
    $is_multiple = $this->fieldDefinition
      ->getFieldStorageDefinition()
      ->isMultiple();
    $field_title = $this->fieldDefinition
      ->getLabel();
    $description = FieldFilteredMarkup::create(\Drupal::token()
      ->replace($this->fieldDefinition
      ->getDescription()));
    $elements = [];
    $tabs = '';
    $this->fieldIdPrefix = implode('-', array_merge($this->fieldParents, [
      $field_name,
    ]));
    $this->fieldWrapperId = Html::getUniqueId($this->fieldIdPrefix . '-add-more-wrapper');

    // If the parent entity is paragraph add the nested class if not then add
    // the perspective tabs.
    $field_prefix = strtr($this->fieldIdPrefix, '_', '-');
    if (count($this->fieldParents) == 0) {
      if ($items
        ->getEntity()
        ->getEntityTypeId() != 'paragraph') {
        $tabs = '<ul class="paragraphs-tabs tabs primary clearfix"><li id="content" class="tabs__tab"><a href="#' . $field_prefix . '-values">Content</a></li><li id="behavior" class="tabs__tab"><a href="#' . $field_prefix . '-values">Behavior</a></li></ul>';
      }
    }
    if (count($this->fieldParents) > 0) {
      if ($items
        ->getEntity()
        ->getEntityTypeId() === 'paragraph') {
        $form['#attributes']['class'][] = 'paragraphs-nested';
      }
    }
    $elements['#prefix'] = '<div class="is-horizontal paragraphs-tabs-wrapper" id="' . $this->fieldWrapperId . '">' . $tabs;
    $elements['#suffix'] = '</div>';
    $field_state['ajax_wrapper_id'] = $this->fieldWrapperId;

    // Persist the widget state so formElement() can access it.
    static::setWidgetState($this->fieldParents, $field_name, $form_state, $field_state);
    $header_actions = $this
      ->buildHeaderActions($field_state, $form_state);
    if ($header_actions) {
      $elements['header_actions'] = $header_actions;

      // Add a weight element so we guaranty that header actions will stay in
      // first row. We will use this later in
      // paragraphs_preprocess_field_multiple_value_form().
      $elements['header_actions']['_weight'] = [
        '#type' => 'weight',
        '#default_value' => -100,
      ];
    }
    if (!empty($field_state['dragdrop'])) {
      $elements['#attached']['library'][] = 'paragraphs/paragraphs-dragdrop';
      $elements['dragdrop'] = $this
        ->buildNestedParagraphsFoDragDrop($form_state, NULL, []);
      return $elements;
    }
    if ($max > 0) {
      for ($delta = 0; $delta < $max; $delta++) {

        // Add a new empty item if it doesn't exist yet at this delta.
        if (!isset($items[$delta])) {
          $items
            ->appendItem();
        }

        // For multiple fields, title and description are handled by the
        // wrapping table.
        $element = [
          '#title' => $is_multiple ? '' : $field_title,
          '#description' => $is_multiple ? '' : $description,
          '#paragraphs_bundle' => '',
        ];
        $element = $this
          ->formSingleElement($items, $delta, $element, $form, $form_state);
        if ($element) {
          $widget_state = static::getWidgetState($element['#field_parents'], $field_name, $form_state);
          $element['#paragraphs_bundle'] = $widget_state['paragraphs'][$delta]['entity']
            ->bundle();

          // Input field for the delta (drag-n-drop reordering).
          if ($is_multiple) {

            // We name the element '_weight' to avoid clashing with elements
            // defined by widget.
            $element['_weight'] = [
              '#type' => 'weight',
              '#title' => $this
                ->t('Weight for row @number', [
                '@number' => $delta + 1,
              ]),
              '#title_display' => 'invisible',
              // This 'delta' is the FAPI #type 'weight' element's property.
              '#delta' => $max,
              '#default_value' => $items[$delta]->_weight ?: $delta,
              '#weight' => 100,
            ];
          }

          // Access for the top element is set to FALSE only when the paragraph
          // was removed. A paragraphs that a user can not edit has access on
          // lower level.
          if (isset($element['#access']) && !$element['#access']) {
            $this->realItemCount--;
          }
          else {
            $elements[$delta] = $element;
          }
        }
      }
    }
    $field_state = static::getWidgetState($this->fieldParents, $field_name, $form_state);
    $field_state['real_item_count'] = $this->realItemCount;
    $field_state['add_mode'] = $this
      ->getSetting('add_mode');
    static::setWidgetState($this->fieldParents, $field_name, $form_state, $field_state);
    $elements += [
      '#element_validate' => [
        [
          $this,
          'multipleElementValidate',
        ],
      ],
      '#required' => $this->fieldDefinition
        ->isRequired(),
      '#field_name' => $field_name,
      '#cardinality' => $cardinality,
      '#max_delta' => $max - 1,
    ];
    if ($this->realItemCount > 0) {
      $elements += [
        '#theme' => 'field_multiple_value_form__paragraphs_sets',
        '#cardinality_multiple' => $is_multiple,
        '#title' => $field_title,
        '#description' => $description,
      ];
    }
    else {
      $classes = $this->fieldDefinition
        ->isRequired() ? [
        'form-required',
      ] : [];
      $elements += [
        '#type' => 'container',
        '#theme_wrappers' => [
          'container',
        ],
        '#cardinality_multiple' => TRUE,
        'title' => [
          '#type' => 'html_tag',
          '#tag' => 'strong',
          '#value' => $field_title,
          '#attributes' => [
            'class' => $classes,
          ],
        ],
        'text' => [
          '#type' => 'container',
          'value' => [
            '#markup' => $this
              ->t('No @title added yet.', [
              '@title' => $this
                ->getSetting('title'),
            ]),
            '#prefix' => '<em>',
            '#suffix' => '</em>',
          ],
        ],
      ];
      if ($description) {
        $elements['description'] = [
          '#type' => 'container',
          'value' => [
            '#markup' => $description,
          ],
          '#attributes' => [
            'class' => [
              'description',
            ],
          ],
        ];
      }
    }
    $this
      ->initIsTranslating($form_state, $host);
    $elements['set_selection'] = $this
      ->buildSelectSetSelection($form_state, $set);
    if (($this->realItemCount < $cardinality || $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) && !$form_state
      ->isProgrammed() && !$this->isTranslating) {
      $elements['add_more'] = $this
        ->buildAddActions();
    }
    $elements['#attached']['library'][] = 'paragraphs/drupal.paragraphs.widget';
    $elements['#attached']['library'][] = 'paragraphs_sets/drupal.paragraphs_sets.admin';
    return $elements;
  }

  /**
   * Builds select element for set selection.
   *
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   * @param string $default
   *   Current selected set.
   *
   * @return array
   *   The form element array.
   */
  protected function buildSelectSetSelection(FormStateInterface $form_state, $default = NULL) {
    $field_name = $this->fieldDefinition
      ->getName();
    $title = $this->fieldDefinition
      ->getLabel();
    $cardinality = $this->fieldDefinition
      ->getFieldStorageDefinition()
      ->getCardinality();
    $options = [
      '_none' => $this
        ->t('- None -'),
    ];
    foreach (static::getSets() as $key => $set) {
      if ($cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && count($set['paragraphs']) > $cardinality) {

        // Do not add sets having more paragraphs than allowed.
        continue;
      }
      $options[$key] = $set['label'];
    }
    $selection_elements = [
      '#type' => 'container',
      '#theme_wrappers' => [
        'container',
      ],
      '#attributes' => [
        'class' => [
          'set-selection-wrapper',
        ],
      ],
    ];
    $selection_elements['set_selection_select'] = [
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => $default,
      '#title' => $this
        ->t('@title set', [
        '@title' => $this
          ->getSetting('title'),
      ]),
      '#label_display' => 'hidden',
    ];
    $selection_elements['set_selection_button'] = [
      '#type' => 'submit',
      '#name' => strtr($this->fieldIdPrefix, '-', '_') . '_set_selection',
      '#value' => $this
        ->t('Select set'),
      '#attributes' => [
        'class' => [
          'field-set-selection-submit',
        ],
      ],
      '#limit_validation_errors' => [
        array_merge($this->fieldParents, [
          $field_name,
          'set_selection',
        ]),
      ],
      '#submit' => [
        [
          get_class($this),
          'setSetSubmit',
        ],
      ],
      '#ajax' => [
        'callback' => [
          get_class($this),
          'setSetAjax',
        ],
        'wrapper' => $this->fieldWrapperId,
        'effect' => 'fade',
      ],
    ];
    $selection_elements['set_selection_button']['#prefix'] = '<div class="paragraphs-set-button paragraphs-set-button-set">';
    $selection_elements['set_selection_button']['#suffix'] = $this
      ->t('for %type', [
      '%type' => $title,
    ]) . '</div>';
    if ($this->realItemCount && ($this->realItemCount < $cardinality || $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) && !$form_state
      ->isProgrammed() && !$this->isTranslating) {
      $selection_elements['append_selection_button'] = [
        '#type' => 'submit',
        '#name' => strtr($this->fieldIdPrefix, '-', '_') . '_append_selection',
        '#value' => $this
          ->t('Append set'),
        '#attributes' => [
          'class' => [
            'field-append-selection-submit',
          ],
        ],
        '#limit_validation_errors' => [
          array_merge($this->fieldParents, [
            $field_name,
            'append_selection',
          ]),
        ],
        '#submit' => [
          [
            get_class($this),
            'setSetSubmit',
          ],
        ],
        '#ajax' => [
          'callback' => [
            get_class($this),
            'setSetAjax',
          ],
          'wrapper' => $this->fieldWrapperId,
          'effect' => 'fade',
        ],
      ];
      $selection_elements['append_selection_button']['#prefix'] = '<div class="paragraphs-set-button paragraphs-set-button-append">';
      $selection_elements['append_selection_button']['#suffix'] = $this
        ->t('to %type', [
        '%type' => $title,
      ]) . '</div>';
    }
    return $selection_elements;
  }

  /**
   * Builds an add paragraph button for opening of modal form.
   *
   * @param array $element
   *   Render element.
   */
  protected function buildModalAddForm(array &$element) {

    // Attach the theme for the dialog template.
    $element['#theme'] = 'paragraphs_sets_add_dialog';
    $element['#buttons_title'] = $this
      ->getSetting('title');
    $element['add_modal_form_area'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'paragraph-type-add-modal',
          'first-button',
        ],
      ],
      '#access' => !$this->isTranslating,
      '#weight' => -2000,
    ];
    $element['add_modal_form_area']['add_more'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Add @title or Set', [
        '@title' => $this
          ->getSetting('title'),
      ]),
      '#name' => 'button_add_modal',
      '#attributes' => [
        'class' => [
          'paragraph-type-add-modal-button',
          'js-show',
        ],
      ],
    ];
    $cardinality = $this->fieldDefinition
      ->getFieldStorageDefinition()
      ->getCardinality();
    foreach (static::getSets() as $machine_name => $set) {
      if ($cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && count($set['paragraphs']) > $cardinality) {

        // Do not add sets having more paragraphs than allowed.
        continue;
      }
      $button_key = 'append_selection_button_' . $machine_name;
      $element[$button_key] = $this
        ->expandButton([
        '#type' => 'submit',
        '#name' => $this->fieldIdPrefix . '_' . $machine_name . '_set_set',
        '#value' => $set['label'],
        '#attributes' => [
          'class' => [
            'field-add-more-submit',
            'field-append-set-submit',
          ],
        ],
        '#limit_validation_errors' => [
          array_merge($this->fieldParents, [
            $this->fieldDefinition
              ->getName(),
            'set_set',
          ]),
        ],
        '#submit' => [
          [
            get_class($this),
            'setSetSubmit',
          ],
        ],
        '#ajax' => [
          'callback' => [
            get_class($this),
            'setSetAjax',
          ],
          'wrapper' => $this->fieldWrapperId,
        ],
        '#set_machine_name' => $machine_name,
      ]);
    }
    $element['#attached']['library'][] = 'paragraphs/drupal.paragraphs.modal';
    $element['#attached']['library'][] = 'paragraphs_sets/drupal.paragraphs_sets.modal';
  }

  /**
   * {@inheritdoc}
   */
  public static function setSetAjax(array $form, FormStateInterface $form_state) {
    $button = $form_state
      ->getTriggeringElement();

    // Go one level up in the form, to the widgets container.
    $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public static function setSetSubmit(array $form, FormStateInterface $form_state) {
    $button = $form_state
      ->getTriggeringElement();

    // Go one level up in the form, to the widgets container.
    $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));
    $field_name = $element['#field_name'];
    $parents = $element['#field_parents'];
    $button_type = end($button['#array_parents']);

    // Increment the items count.
    $widget_state = static::getWidgetState($parents, $field_name, $form_state);
    $widget_state['button_type'] = $button_type;
    if (isset($button['#set_machine_name'])) {
      $widget_state['selected_set'] = $button['#set_machine_name'];
    }
    else {
      $widget_state['selected_set'] = $element['set_selection']['set_selection_select']['#value'];
    }
    static::setWidgetState($parents, $field_name, $form_state, $widget_state);
    $form_state
      ->setRebuild();
  }

  /**
   * Get the list of all defined sets.
   *
   * @return array
   *   List of sets keyed by set ID.
   */
  public static function getSets() {
    $query = \Drupal::entityQuery('paragraphs_set');
    $config_factory = \Drupal::configFactory();
    $results = $query
      ->execute();
    $sets = [];
    foreach ($results as $id) {

      /** @var \Drupal\Core\Config\ImmutableConfig $config */
      if ($config = $config_factory
        ->get("paragraphs_sets.set.{$id}")) {
        $sets[$id] = $config
          ->getRawData();
      }
    }
    return $sets;
  }

  /**
   * Returns the default paragraph type.
   *
   * @return string
   *   Label name for default paragraph type.
   */
  protected function getDefaultParagraphTypeLabelName() {
    if ($this
      ->getDefaultParagraphTypeMachineName() !== NULL) {
      $allowed_types = static::getSets();
      return $allowed_types[$this
        ->getDefaultParagraphTypeMachineName()]['label'];
    }
    return NULL;
  }

  /**
   * Returns the machine name for default paragraph set.
   *
   * @return string
   *   Machine name for default paragraph set.
   */
  protected function getDefaultParagraphTypeMachineName() {
    $default_type = $this
      ->getSetting('default_paragraph_type');
    $allowed_types = static::getSets();
    if ($default_type && isset($allowed_types[$default_type])) {
      return $default_type;
    }

    // Check if the user explicitly selected not to have any default Paragraph
    // set. Otherwise, if there is only one set available, that one is the
    // default.
    if ($default_type === '_none') {
      return NULL;
    }
    if (count($allowed_types) === 1) {
      return key($allowed_types);
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AllowedTagsXssTrait::allowedTags public function Returns a list of tags allowed by AllowedTagsXssTrait::fieldFilterXss().
AllowedTagsXssTrait::displayAllowedTags public function Returns a human-readable list of allowed tags for display in help texts.
AllowedTagsXssTrait::fieldFilterXss public function Filters an HTML string to prevent XSS vulnerabilities.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
ParagraphsWidget::$accessOptions protected property Accessible paragraphs types.
ParagraphsWidget::$fieldIdPrefix protected property Id to name ajax buttons that includes field parents and field name.
ParagraphsWidget::$fieldParents protected property Parents for the current paragraph.
ParagraphsWidget::$fieldWrapperId protected property Wrapper id to identify the paragraphs.
ParagraphsWidget::$isTranslating protected property Indicates whether the current widget instance is in translation.
ParagraphsWidget::$realItemCount protected property Number of paragraphs item on form.
ParagraphsWidget::ACTION_POSITION_ACTIONS constant Action position is in the actions section of the widget.
ParagraphsWidget::ACTION_POSITION_BASE constant Action position is in the add paragraphs place.
ParagraphsWidget::ACTION_POSITION_HEADER constant Action position is in the table header section.
ParagraphsWidget::addMoreAjax public static function Ajax callback for the "Add another item" button. Overrides WidgetBase::addMoreAjax
ParagraphsWidget::addMoreSubmit public static function Submission handler for the "Add another item" button. Overrides WidgetBase::addMoreSubmit
ParagraphsWidget::addTranslatabilityClue public static function After-build callback for adding the translatability clue from the widget.
ParagraphsWidget::allActionsAjax public static function Ajax callback for all actions.
ParagraphsWidget::allowReferenceChanges protected function Checks if we can allow reference changes.
ParagraphsWidget::autocollapse public static function Returns a state with all paragraphs closed, if autocollapse is enabled.
ParagraphsWidget::buildAddActions protected function Add 'add more' button, if not working with a programmed form.
ParagraphsWidget::buildButtonsAddMode protected function Builds dropdown button for adding new paragraph.
ParagraphsWidget::buildDropbutton protected function Build drop button.
ParagraphsWidget::buildHeaderActions public function Builds header actions.
ParagraphsWidget::buildModalAddForm protected function Builds an add paragraph button for opening of modal form. Overrides ParagraphsWidget::buildModalAddForm
ParagraphsWidget::buildNestedParagraphsFoDragDrop protected function Builds the nested drag and drop structure.
ParagraphsWidget::buildSelectAddMode protected function Builds list of actions based on paragraphs type.
ParagraphsWidget::buildSelectSetSelection protected function Builds select element for set selection.
ParagraphsWidget::changeAllEditModeSubmit public static function Loops through all paragraphs and change mode for each paragraph instance.
ParagraphsWidget::createMessage public function Helper to create a paragraph UI message.
ParagraphsWidget::defaultSettings public static function Defines the default settings for this plugin. Overrides PluginSettingsBase::defaultSettings
ParagraphsWidget::dragDropModeAjax public static function Ajax callback for the dragdrop mode.
ParagraphsWidget::dragDropModeSubmit public static function Sets the form mode accordingly.
ParagraphsWidget::duplicateButtonAccess protected function Check duplicate button access.
ParagraphsWidget::duplicateSubmit public static function Creates a duplicate of the paragraph entity.
ParagraphsWidget::elementValidate public function
ParagraphsWidget::errorElement public function Assigns a field-level validation error to the right widget sub-element. Overrides WidgetBase::errorElement
ParagraphsWidget::expandButton public static function Expand button base array into a paragraph widget action button.
ParagraphsWidget::extractFormValues public function Extracts field values from submitted form values. Overrides WidgetBase::extractFormValues
ParagraphsWidget::flagErrors public function Reports field-level validation errors against actual form elements. Overrides WidgetBase::flagErrors
ParagraphsWidget::form public function Creates a form element for a field. Overrides WidgetBase::form
ParagraphsWidget::formElement public function Uses a similar approach to populate a new translation. Overrides WidgetInterface::formElement
ParagraphsWidget::formMultipleElements public function Special handling to create form elements for multiple values. Overrides ParagraphsWidget::formMultipleElements
ParagraphsWidget::getAccessibleOptions protected function Returns the available paragraphs type.
ParagraphsWidget::getAllowedTypes public function Returns the sorted allowed types for a entity reference field.
ParagraphsWidget::getChildParagraphs protected function Returns a list of child paragraphs for a given field to loop over.
ParagraphsWidget::getDefaultParagraphTypeLabelName protected function Returns the default paragraph type. Overrides ParagraphsWidget::getDefaultParagraphTypeLabelName
ParagraphsWidget::getDefaultParagraphTypeMachineName protected function Returns the machine name for default paragraph set. Overrides ParagraphsWidget::getDefaultParagraphTypeMachineName
ParagraphsWidget::getNumberOfParagraphsInMode protected function Counts the number of paragraphs in a certain mode in a form substructure.
ParagraphsWidget::getSelectionHandlerSetting protected function Returns the value of a setting for the entity reference selection handler.
ParagraphsWidget::getSets public static function Get the list of all defined sets.
ParagraphsWidget::getSettingOptions protected function Returns select options for a plugin setting.
ParagraphsWidget::getSubmitElementInfo public static function Get common submit element information for processing ajax submit handlers.
ParagraphsWidget::initIsTranslating protected function Determine if widget is in translation.
ParagraphsWidget::isApplicable public static function Returns if the widget can be used for the provided field. Overrides WidgetBase::isApplicable
ParagraphsWidget::isFeatureEnabled protected function Checks if a widget feature is enabled or not.
ParagraphsWidget::itemAjax public static function
ParagraphsWidget::massageFormValues public function Massages the form values into the format expected for field values. Overrides WidgetBase::massageFormValues
ParagraphsWidget::multipleElementValidate public function Special handling to validate form elements with multiple values.
ParagraphsWidget::paragraphsItemSubmit public static function
ParagraphsWidget::prepareDeltaPosition protected static function Prepares the widget state to add a new paragraph at a specific position.
ParagraphsWidget::removeButtonAccess protected function Check remove button access.
ParagraphsWidget::reorderParagraphs protected static function Reorder paragraphs.
ParagraphsWidget::setSetAjax public static function
ParagraphsWidget::setSetSubmit public static function
ParagraphsWidget::settingsForm public function Returns a form to configure settings for the widget. Overrides ParagraphsWidget::settingsForm
ParagraphsWidget::settingsSummary public function Returns a short summary for the current widget settings. Overrides ParagraphsWidget::settingsSummary
ParagraphsWidget::__construct public function Constructs a ParagraphsWidget object. Overrides WidgetBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginSettingsBase::$defaultSettingsMerged protected property Whether default settings have been merged into the current $settings.
PluginSettingsBase::$thirdPartySettings protected property The plugin settings injected by third party modules.
PluginSettingsBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies 6
PluginSettingsBase::getSetting public function Returns the value of a setting, or its default value if absent. Overrides PluginSettingsInterface::getSetting
PluginSettingsBase::getSettings public function Returns the array of settings, including defaults for missing settings. Overrides PluginSettingsInterface::getSettings
PluginSettingsBase::getThirdPartyProviders public function Gets the list of third parties that store information. Overrides ThirdPartySettingsInterface::getThirdPartyProviders
PluginSettingsBase::getThirdPartySetting public function Gets the value of a third-party setting. Overrides ThirdPartySettingsInterface::getThirdPartySetting
PluginSettingsBase::getThirdPartySettings public function Gets all third-party settings of a given module. Overrides ThirdPartySettingsInterface::getThirdPartySettings
PluginSettingsBase::mergeDefaults protected function Merges default settings values into $settings.
PluginSettingsBase::onDependencyRemoval public function Informs the plugin that some configuration it depends on will be deleted. Overrides PluginSettingsInterface::onDependencyRemoval 3
PluginSettingsBase::setSetting public function Sets the value of a setting for the plugin. Overrides PluginSettingsInterface::setSetting
PluginSettingsBase::setSettings public function Sets the settings for the plugin. Overrides PluginSettingsInterface::setSettings
PluginSettingsBase::setThirdPartySetting public function Sets the value of a third-party setting. Overrides ThirdPartySettingsInterface::setThirdPartySetting
PluginSettingsBase::unsetThirdPartySetting public function Unsets a third-party setting. Overrides ThirdPartySettingsInterface::unsetThirdPartySetting
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WidgetBase::$fieldDefinition protected property The field definition.
WidgetBase::$settings protected property The widget settings. Overrides PluginSettingsBase::$settings
WidgetBase::afterBuild public static function After-build handler for field elements in a form.
WidgetBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 5
WidgetBase::formSingleElement protected function Generates the form element for a single copy of the widget.
WidgetBase::getFieldSetting protected function Returns the value of a field setting.
WidgetBase::getFieldSettings protected function Returns the array of field settings.
WidgetBase::getFilteredDescription protected function Returns the filtered field description.
WidgetBase::getWidgetState public static function Retrieves processing information about the widget from $form_state. Overrides WidgetBaseInterface::getWidgetState
WidgetBase::getWidgetStateParents protected static function Returns the location of processing information within $form_state.
WidgetBase::handlesMultipleValues protected function Returns whether the widget handles multiple values.
WidgetBase::isDefaultValueWidget protected function Returns whether the widget used for default value form.
WidgetBase::setWidgetState public static function Stores processing information about the widget in $form_state. Overrides WidgetBaseInterface::setWidgetState