You are here

public function Paragraph::getIcons in Paragraphs 8

Returns info icons render array for a paragraph.

Parameters

array $options: (optional) Array of additional options, with the following elements:

  • 'show_behavior_icon': Whether the icons should contain the behavior settings. Defaults to TRUE to show behavior icons in the summary.

Return value

array A list of render arrays that will be rendered as icons.

Overrides ParagraphInterface::getIcons

File

src/Entity/Paragraph.php, line 549

Class

Paragraph
Defines the Paragraph entity.

Namespace

Drupal\paragraphs\Entity

Code

public function getIcons(array $options = []) {
  $show_behavior_info = isset($options['show_behavior_icon']) ? $options['show_behavior_icon'] : TRUE;
  $icons = [];

  // For now we depend here on the fact that summaryCount is already
  // initialized. That means that getSummary() should be called before
  // getIcons().
  // @todo - should we fix this dependency somehow?
  if ($this->summaryCount) {
    $icons['count'] = [
      '#markup' => $this->summaryCount,
      '#prefix' => '<span class="paragraphs-badge" title="' . (string) \Drupal::translation()
        ->formatPlural($this->summaryCount, '1 child', '@count children') . '">',
      '#suffix' => '</span>',
    ];
  }
  if ($show_behavior_info) {
    $paragraphs_type = $this
      ->getParagraphType();
    foreach ($paragraphs_type
      ->getEnabledBehaviorPlugins() as $plugin) {
      if ($plugin_info = $plugin
        ->settingsIcon($this)) {
        $icons = array_merge($icons, $plugin_info);
      }
    }
  }
  return $icons;
}