You are here

public function ChooseComponentController::getComponentTypes in Layout Paragraphs 2.0.x

Returns an array of available component types.

Parameters

\Drupal\layout_paragraphs\LayoutParagraphsLayout $layout: The layout paragraphs layout.

Return value

array An array of available component types.

1 call to ChooseComponentController::getComponentTypes()
ChooseComponentController::getAllowedComponentTypes in src/Controller/ChooseComponentController.php
Returns an array of allowed component types.

File

src/Controller/ChooseComponentController.php, line 176

Class

ChooseComponentController
ChooseComponentController controller class.

Namespace

Drupal\layout_paragraphs\Controller

Code

public function getComponentTypes(LayoutParagraphsLayout $layout) {
  $items = $layout
    ->getParagraphsReferenceField();
  $settings = $items
    ->getSettings()['handler_settings'];
  $sorted_bundles = $this
    ->getSortedAllowedTypes($settings);
  $storage = $this
    ->entityTypeManager()
    ->getStorage('paragraphs_type');
  foreach (array_keys($sorted_bundles) as $bundle) {

    /** @var \Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type */
    $paragraphs_type = $storage
      ->load($bundle);
    $plugins = $paragraphs_type
      ->getEnabledBehaviorPlugins();
    $section_component = isset($plugins['layout_paragraphs']);
    $path = '';

    // Get the icon and pass to Javascript.
    if (method_exists($paragraphs_type, 'getIconUrl')) {
      $path = $paragraphs_type
        ->getIconUrl();
    }
    $types[$bundle] = [
      'id' => $paragraphs_type
        ->id(),
      'label' => $paragraphs_type
        ->label(),
      'image' => $path,
      'description' => $paragraphs_type
        ->getDescription(),
      'is_section' => $section_component,
    ];
  }
  return $types;
}