You are here

public function ParagraphBlocksLabeller::hookLayoutBuilderChooseBlocksAlter in Paragraph blocks 8.2

Same name and namespace in other branches
  1. 3.x src/ParagraphBlocksLabeller.php \Drupal\paragraph_blocks\ParagraphBlocksLabeller::hookLayoutBuilderChooseBlocksAlter()

Removed unused paragraphs and update the layout builder title.

Parameters

array $definitions: The plugin definitions.

File

src/ParagraphBlocksLabeller.php, line 109

Class

ParagraphBlocksLabeller
Labels the paragraph blocks once the entity context is known.

Namespace

Drupal\paragraph_blocks

Code

public function hookLayoutBuilderChooseBlocksAlter(array &$definitions) {

  // Loop through all of the plugin definitions.
  foreach ($definitions as $plugin_id => $definition) {
    $enabled = TRUE;
    $title = $this
      ->getTitle($plugin_id, $enabled);
    if ($title === FALSE) {

      // Remove the block if there is no paragraph data for the delta.
      if ($this->entity || !$enabled) {
        unset($definitions[$plugin_id]);
      }
    }
    elseif ($title) {

      // Replace the title.
      $definitions[$plugin_id]['admin_label'] = $title;
    }
  }
}