You are here

public function TestBoldTextBehavior::view in Paragraphs 8

Extends the paragraph render array with behavior.

Parameters

array &$build: A renderable array representing the paragraph. The module may add elements to $build prior to rendering. The structure of $build is a renderable array as expected by drupal_render().

\Drupal\paragraphs\Entity\Paragraph $paragraph: The paragraph.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

string $view_mode: The view mode the entity is rendered in.

Return value

array A render array provided by the plugin.

Overrides ParagraphsBehaviorInterface::view

File

tests/modules/paragraphs_test/src/Plugin/paragraphs/Behavior/TestBoldTextBehavior.php, line 40

Class

TestBoldTextBehavior
Provides a test feature plugin.

Namespace

Drupal\paragraphs_test\Plugin\paragraphs\Behavior

Code

public function view(array &$build, Paragraph $paragraphs_entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($paragraphs_entity
    ->getBehaviorSetting($this
    ->getPluginId(), 'bold_text')) {
    $build['#attributes']['class'][] = 'bold_plugin_text';
    $build['#attached']['library'][] = 'paragraphs_test/drupal.paragraphs_test.bold_text';
  }
}