public function ParagraphsAnchorPlugin::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/ ParagraphsAnchorPlugin.php, line 66
Class
- ParagraphsAnchorPlugin
- Provides a Paragraphs Anchor plugin.
Namespace
Drupal\paragraphs_collection_demo\Plugin\paragraphs\BehaviorCode
public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode) {
if ($anchor = $paragraph
->getBehaviorSetting($this
->getPluginId(), 'anchor')) {
$build['#attributes']['id'] = 'scrollto-' . $anchor;
$build['#attributes']['class'][] = 'paragraphs-anchor-link';
// @todo Make UI for global configuration.
// @see https://www.drupal.org/node/2856912.
if ($this->configFactory
->get('paragraphs_collection_demo.settings')
->get('anchor')['show_permalink']) {
$build['#attached']['library'][] = 'paragraphs_collection_demo/anchor';
}
}
}