class TextAlignment in Bootstrap Styles 1.0.x
Class TextAlignment.
@package Drupal\bootstrap_styles\Plugin\Style
Plugin annotation
@Style(
id = "text_alignment",
title = @Translation("Text Alignment"),
group_id = "typography",
weight = 2
)
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\TextAlignment
- class \Drupal\bootstrap_styles\Style\StylePluginBase implements StylePluginInterface uses StringTranslationTrait
Expanded class hierarchy of TextAlignment
File
- src/
Plugin/ BootstrapStyles/ Style/ TextAlignment.php, line 20
Namespace
Drupal\bootstrap_styles\Plugin\BootstrapStyles\StyleView source
class TextAlignment extends StylePluginBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$config = $this
->config();
$form['typography']['text_alignment'] = [
'#type' => 'textarea',
'#default_value' => $config
->get('text_alignment'),
'#title' => $this
->t('Text alignment (classes)'),
'#description' => $this
->t('<p>Enter one value per line, in the format <b>key|label</b> where <em>key</em> is the CSS class name (without the .), and <em>label</em> is the human readable name of the text.</p>'),
'#cols' => 60,
'#rows' => 5,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this
->config()
->set('text_alignment', $form_state
->getValue('text_alignment'))
->save();
}
/**
* {@inheritdoc}
*/
public function buildStyleFormElements(array &$form, FormStateInterface $form_state, $storage) {
$form['text_alignment'] = [
'#type' => 'radios',
'#options' => $this
->getStyleOptions('text_alignment'),
'#title' => $this
->t('Alignment'),
'#default_value' => $storage['text_alignment']['class'] ?? NULL,
'#validated' => TRUE,
'#attributes' => [
'class' => [
'field-text-alignment',
'bs_input-boxes',
],
],
];
// Add icons to the container types.
foreach ($form['text_alignment']['#options'] as $key => $value) {
$form['text_alignment']['#options'][$key] = '<span class="input-icon ' . $key . '"></span>' . $value;
}
// Attach the Layout Builder form style for this plugin.
$form['#attached']['library'][] = 'bootstrap_styles/plugin.text_alignment.layout_builder_form';
return $form;
}
/**
* {@inheritdoc}
*/
public function submitStyleFormElements(array $group_elements) {
return [
'text_alignment' => [
'class' => $group_elements['text_alignment'],
],
];
}
/**
* {@inheritdoc}
*/
public function build(array $build, array $storage, $theme_wrapper = NULL) {
$classes = [];
if (isset($storage['text_alignment']['class'])) {
$classes[] = $storage['text_alignment']['class'];
}
// Add the classes to the build.
$build = $this
->addClassesToBuild($build, $classes, $theme_wrapper);
// Attach bs-classes to the build.
$build['#attached']['library'][] = 'bootstrap_styles/plugin.text_alignment.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. | |
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 |
TextAlignment:: |
public | function |
Overrides StylePluginBase:: |
|
TextAlignment:: |
public | function |
Overrides StylePluginBase:: |
|
TextAlignment:: |
public | function |
Overrides StylePluginBase:: |
|
TextAlignment:: |
public | function |
Overrides StylePluginBase:: |
|
TextAlignment:: |
public | function |
Overrides StylePluginBase:: |