class ScrollEffects in Bootstrap Styles 1.0.x
Class Effect.
@package Drupal\bootstrap_styles\Plugin\Style
Plugin annotation
@Style(
id = "scroll_effects",
title = @Translation("Scroll Effects"),
group_id = "animation",
weight = 3
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\bootstrap_styles\Style\StylePluginBase implements StylePluginInterface uses StringTranslationTrait
- class \Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style\ScrollEffects
- class \Drupal\bootstrap_styles\Style\StylePluginBase implements StylePluginInterface uses StringTranslationTrait
Expanded class hierarchy of ScrollEffects
File
- src/
Plugin/ BootstrapStyles/ Style/ ScrollEffects.php, line 20
Namespace
Drupal\bootstrap_styles\Plugin\BootstrapStyles\StyleView source
class ScrollEffects extends StylePluginBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$config = $this
->config();
// Library assets.
$form['animation']['scroll_effects_library_type'] = [
'#type' => 'select',
'#default_value' => $config
->get('scroll_effects_library_type'),
'#title' => $this
->t('How should we load the animation library?'),
'#required' => TRUE,
'#options' => [
'local' => $this
->t('Do nothing, my theme handle it'),
'external' => $this
->t('Add the library for me please'),
],
'#description' => $this
->t('<p>Default uses the AOS library: <a href="https://michalsnik.github.io/aos" target="_blank">https://michalsnik.github.io/aos</a><br/> You can override the animation library in your theme by using <br /><code>libraries-override:<br /> bootstrap_styles/plugin.scroll_effects.build: your_theme/your_new_library_definition</code><br /><small>For more information, please check: <a href="https://www.drupal.org/node/2497313" target="_blank">https://www.drupal.org/node/2497313</a></small></p>'),
];
$form['animation']['scroll_effects'] = [
'#type' => 'textarea',
'#default_value' => $config
->get('scroll_effects'),
'#title' => $this
->t('Scroll Effects'),
'#description' => $this
->t('<p>Enter one value per line, in the format <b>key|label</b> where <em>key</em> is the attribute\'s value, and <em>label</em> is the human readable name of the effect.</p>'),
'#cols' => 60,
'#rows' => 5,
];
$form['animation']['scroll_effects_attr_type'] = [
'#type' => 'checkbox',
'#default_value' => $config
->get('scroll_effects_attr_type'),
'#title' => $this
->t('Use data attribute instead of class.'),
];
$form['animation']['scroll_effects_data_key'] = [
'#type' => 'textfield',
'#default_value' => $config
->get('scroll_effects_data_key'),
'#title' => $this
->t('Data Key'),
'#description' => $this
->t('<p>The <strong>data_key</strong> will be used as the data attribute. Example: <code>data_key="key"</code></p>'),
'#states' => [
'visible' => [
[
[
':input[name="scroll_effects_attr_type"]' => [
'checked' => TRUE,
],
],
],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this
->config()
->set('scroll_effects_library_type', $form_state
->getValue('scroll_effects_library_type'))
->set('scroll_effects_attr_type', $form_state
->getValue('scroll_effects_attr_type'))
->set('scroll_effects_data_key', $form_state
->getValue('scroll_effects_data_key'))
->set('scroll_effects', $form_state
->getValue('scroll_effects'))
->save();
}
/**
* {@inheritdoc}
*/
public function buildStyleFormElements(array &$form, FormStateInterface $form_state, $storage) {
$form['scroll_effects'] = [
'#type' => 'radios',
'#options' => $this
->getStyleOptions('scroll_effects'),
'#title' => $this
->t('Scroll Effects'),
'#default_value' => $storage['scroll_effects']['class'] ?? NULL,
'#validated' => TRUE,
'#attributes' => [
'class' => [
'field-scroll-effects',
],
],
'#prefix' => '<span class="input-icon"></span>',
];
// Add icons to the effets.
foreach ($form['scroll_effects']['#options'] as $key => $value) {
$form['scroll_effects']['#options'][$key] = '<span class="input-icon ' . $key . '"></span>' . $value;
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitStyleFormElements(array $group_elements) {
return [
'scroll_effects' => [
'class' => $group_elements['scroll_effects'],
],
];
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ScrollEffects:: |
public | function |
Overrides StylePluginBase:: |
|
ScrollEffects:: |
public | function |
Overrides StylePluginBase:: |
|
ScrollEffects:: |
public | function |
Overrides StylePluginBase:: |
|
ScrollEffects:: |
public | function |
Overrides StylePluginBase:: |
|
ScrollEffects:: |
public | function |
Overrides StylePluginBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
StylePluginBase:: |
protected | property | The config factory. | |
StylePluginBase:: |
public | function | Helper function to add the classes to the build. | |
StylePluginBase:: |
public | function | ||
StylePluginBase:: |
constant | Config settings. | ||
StylePluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
StylePluginBase:: |
public | function | Helper function to get the class from the options list. | |
StylePluginBase:: |
public | function | Helper function to get the index of the class at options list. | |
StylePluginBase:: |
public | function | Helper function to get the options of given style name. | |
StylePluginBase:: |
public | function | Helper function to get the options of given style name. | |
StylePluginBase:: |
public | function | Helper function to get SVG Markup. | |
StylePluginBase:: |
public | function |
Return the name of the Styles Group form plugin. Overrides StylePluginInterface:: |
|
StylePluginBase:: |
public | function | ||
StylePluginBase:: |
public | function |
Constructs a StylePluginBase object. Overrides PluginBase:: |
1 |