You are here

public function ScrollEffects::build in Bootstrap Styles 1.0.x

Overrides StylePluginBase::build

File

src/Plugin/BootstrapStyles/Style/ScrollEffects.php, line 123

Class

ScrollEffects
Class Effect.

Namespace

Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style

Code

public function build(array $build, array $storage, $theme_wrapper = NULL) {
  $library_type = $this
    ->config()
    ->get('scroll_effects_library_type');
  $attribute_type = $this
    ->config()
    ->get('scroll_effects_attr_type');
  $data_key = $this
    ->config()
    ->get('scroll_effects_data_key');

  // Assign the style to element or its theme wrapper if exist.
  if ($theme_wrapper && isset($build['#theme_wrappers'][$theme_wrapper])) {
    if (isset($attribute_type) && $attribute_type === 1) {

      // Output some sort of data attribute.
      $build['#theme_wrappers'][$theme_wrapper]['#attributes'][$data_key][] = $storage['scroll_effects']['class'];
    }
    else {

      // Output classes.
      $build['#theme_wrappers'][$theme_wrapper]['#attributes']['class'][] = $storage['scroll_effects']['class'];
    }
  }
  else {
    if (isset($attribute_type) && $attribute_type === 1) {

      // Output some sort of data attribute.
      $build['#attributes'][$data_key][] = $storage['scroll_effects']['class'];
    }
    else {

      // Output classes.
      $build['#attributes']['class'][] = $storage['scroll_effects']['class'];
    }
  }
  if (isset($library_type) && $library_type === 'external') {
    $build['#attached']['library'][] = 'bootstrap_styles/plugin.scroll_effects.build';
  }
  return $build;
}