You are here

public function InlineParagraphsWidget::getAllowedTypes in Paragraphs 8

Returns the sorted allowed types for a entity reference field.

Return value

array A list of arrays keyed by the paragraph type machine name with the following properties.

  • label: The label of the paragraph type.
  • weight: The weight of the paragraph type.
5 calls to InlineParagraphsWidget::getAllowedTypes()
InlineParagraphsWidget::buildAddActions in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Add 'add more' button, if not working with a programmed form.
InlineParagraphsWidget::getAccessibleOptions in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Returns the available paragraphs type.
InlineParagraphsWidget::getDefaultParagraphTypeLabelName in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Returns the default paragraph type.
InlineParagraphsWidget::getDefaultParagraphTypeMachineName in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Returns the machine name for default paragraph type.
InlineParagraphsWidget::settingsForm in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Returns a form to configure settings for the widget.

File

src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 750

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public function getAllowedTypes() {
  $return_bundles = array();

  /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $selection_manager */
  $selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
  $handler = $selection_manager
    ->getSelectionHandler($this->fieldDefinition);
  if ($handler instanceof ParagraphSelection) {
    $return_bundles = $handler
      ->getSortedAllowedTypes();
  }
  else {
    $bundles = \Drupal::service('entity_type.bundle.info')
      ->getBundleInfo($this
      ->getFieldSetting('target_type'));
    $weight = 0;
    foreach ($bundles as $machine_name => $bundle) {
      if (empty($this
        ->getSelectionHandlerSetting('target_bundles')) || in_array($machine_name, $this
        ->getSelectionHandlerSetting('target_bundles'))) {
        $return_bundles[$machine_name] = array(
          'label' => $bundle['label'],
          'weight' => $weight,
        );
        $weight++;
      }
    }
  }
  return $return_bundles;
}