You are here

protected function ParagraphEntityForm::getAllowedBundles in Paragraphs Inline Entity Form 8

Same name and namespace in other branches
  1. 2.x src/Plugin/EntityBrowser/Widget/ParagraphEntityForm.php \Drupal\paragraphs_inline_entity_form\Plugin\EntityBrowser\Widget\ParagraphEntityForm::getAllowedBundles()
  2. 2.0.x src/Plugin/EntityBrowser/Widget/ParagraphEntityForm.php \Drupal\paragraphs_inline_entity_form\Plugin\EntityBrowser\Widget\ParagraphEntityForm::getAllowedBundles()

Returns a list of allowed Paragraph bundles to add.

Parameters

array $allowed_bundles: An array with Paragraph bundles which are allowed to add.

Return value

array Array with allowed Paragraph bundles.

1 call to ParagraphEntityForm::getAllowedBundles()
ParagraphEntityForm::entitySelectorForm in src/Plugin/EntityBrowser/Widget/ParagraphEntityForm.php

File

src/Plugin/EntityBrowser/Widget/ParagraphEntityForm.php, line 155

Class

ParagraphEntityForm
A wrapper for EntityForm to provide a two step form where on the first step the user can select the Entity type and on the second step, to create content

Namespace

Drupal\paragraphs_inline_entity_form\Plugin\EntityBrowser\Widget

Code

protected function getAllowedBundles($allowed_bundles = NULL) {
  $bundles = $this->entityTypeBundleInfo
    ->getBundleInfo('paragraph');
  if (is_array($allowed_bundles) && count($allowed_bundles)) {

    // Preserve order of allowed bundles setting.
    $allowed_bundles_order = array_flip($allowed_bundles);

    // Only keep allowed bundles.
    $bundles = array_intersect_key(array_replace($allowed_bundles_order, $bundles), $allowed_bundles_order);
  }

  // Enrich bundles with their label.
  foreach ($bundles as $bundle => $props) {
    $label = empty($props['label']) ? ucfirst($bundle) : $props['label'];
    $bundles[$bundle] = $label;
  }
  return $bundles;
}