public function ParagraphsBackgroundPlugin::view in Paragraphs Collection 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
- modules/
paragraphs_collection_demo/ src/ Plugin/ paragraphs/ Behavior/ ParagraphsBackgroundPlugin.php, line 81
Class
- ParagraphsBackgroundPlugin
- Provides a background image feature plugin.
Namespace
Drupal\paragraphs_collection_demo\Plugin\paragraphs\BehaviorCode
public function view(array &$build, Paragraph $paragraphs_entity, EntityViewDisplayInterface $display, $view_mode) {
$build['#attributes']['class'][] = 'paragraphs-behavior-background';
$build['#attached']['library'][] = 'paragraphs_collection_demo/background';
foreach (Element::children($build) as $field) {
if ($field == $this->configuration['background_image_field']) {
// Put the selected field into the background.
$build[$field]['#attributes']['class'][] = 'paragraphs-behavior-background--image';
}
else {
// Identify all other elements to put them on top of the background.
$build[$field]['#attributes']['class'][] = 'paragraphs-behavior-background--element';
}
}
}