You are here

class TextColor in Bootstrap Styles 1.0.x

Class TextColor.

@package Drupal\bootstrap_styles\Plugin\Style

Plugin annotation


@Style(
  id = "text_color",
  title = @Translation("Text Color"),
  group_id = "typography",
  weight = 1
)

Hierarchy

Expanded class hierarchy of TextColor

File

src/Plugin/BootstrapStyles/Style/TextColor.php, line 21

Namespace

Drupal\bootstrap_styles\Plugin\BootstrapStyles\Style
View source
class TextColor extends StylePluginBase {
  use ResponsiveTrait;

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config();
    $form['typography']['text_colors'] = [
      '#type' => 'textarea',
      '#default_value' => $config
        ->get('text_colors'),
      '#title' => $this
        ->t('Text colors (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,
    ];

    // Responsive.
    $fields = [
      'text_colors' => [
        'typography',
      ],
    ];
    $this
      ->buildBreakpointsConfigurationForm($form, $fields);
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config()
      ->set('text_colors', $form_state
      ->getValue('text_colors'))
      ->save();

    // Responsive.
    $fields = [
      'text_colors',
    ];
    $this
      ->submitBreakpointsConfigurationForm($form_state, $fields);
  }

  /**
   * {@inheritdoc}
   */
  public function buildStyleFormElements(array &$form, FormStateInterface $form_state, $storage) {
    $form['text_color'] = [
      '#type' => 'radios',
      '#options' => $this
        ->getStyleOptions('text_colors'),
      '#title' => $this
        ->t('Text Color'),
      '#default_value' => $storage['text_color']['class'] ?? NULL,
      '#validated' => TRUE,
      '#attributes' => [
        'class' => [
          'field-text-color',
          'bs_input-circles',
          'with-selected-gradient',
        ],
      ],
    ];

    // Responsive.
    $this
      ->createBreakpointsStyleFormFields($form, 'text_color', 'typography', $storage, 'text_colors');

    // Attach the Layout Builder form style for this plugin.
    $form['#attached']['library'][] = 'bootstrap_styles/plugin.text_color.layout_builder_form';
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitStyleFormElements(array $group_elements) {
    $storage = [
      'text_color' => [
        'class' => $group_elements['text_color'],
      ],
    ];

    // Responsive.
    $fields = [
      'text_color',
    ];
    $this
      ->saveBreakpointsStyleFormFields($group_elements, $storage, $fields);
    return $storage;
  }

  /**
   * {@inheritdoc}
   */
  public function build(array $build, array $storage, $theme_wrapper = NULL) {
    $classes = [];
    if (isset($storage['text_color']['class'])) {
      $classes[] = $storage['text_color']['class'];
    }

    // Responsive.
    $fields = [
      'text_color',
    ];
    $this
      ->buildBreakpoints($classes, $storage, $fields);

    // 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_color.build';
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HelperTrait::getSvgIconMarkup public function Generates the svg markup from path.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
ResponsiveTrait::buildBreakpoints protected function Add the breakpoints classes to the build classes.
ResponsiveTrait::buildBreakpointsConfigurationForm protected function TODO: Remove and replace this function.
ResponsiveTrait::buildBreakpointsFields protected function Build the breakpoints style form elements.
ResponsiveTrait::buildBreakpointsStyleFormElements protected function TODO: RENAME Build the breakpoints style form elements.
ResponsiveTrait::buildResponsivePreviewer protected function Build the responsive previewer form elements.
ResponsiveTrait::createBreakpointFormField protected function Build the breakpoints configuration form.
ResponsiveTrait::createBreakpointsStyleFormClassIndexBasedFields protected function Create breakpoints fields for class index based field like padding.
ResponsiveTrait::createBreakpointsStyleFormFields protected function Create breakpoints fields for a given field.
ResponsiveTrait::createBreakpointStyleFormClassIndexBasedField protected function Create breakpoint field for class index based field like padding.
ResponsiveTrait::createBreakpointStyleFormField protected function Create breakpoint field for a given field.
ResponsiveTrait::getBreakpoints protected function The available breakpoint.
ResponsiveTrait::getBreakpointsKeys protected function The available breakpoint.
ResponsiveTrait::getBreakpointTitle protected function Get breakpoint title by key.
ResponsiveTrait::saveBreakpointsStyleFormClassIndexBasedFields protected function Save the breakpoints fields values to the storage.
ResponsiveTrait::saveBreakpointsStyleFormFields protected function Save the breakpoints fields values to the storage.
ResponsiveTrait::submitBreakpointsConfigurationForm protected function Save the breakpoints fields values to the configuration.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
StylePluginBase::$configFactory protected property The config factory.
StylePluginBase::addClassesToBuild public function Helper function to add the classes to the build.
StylePluginBase::config public function
StylePluginBase::CONFIG constant Config settings.
StylePluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
StylePluginBase::getStyleOptionClassByIndex public function Helper function to get the class from the options list.
StylePluginBase::getStyleOptionIndexByClass public function Helper function to get the index of the class at options list.
StylePluginBase::getStyleOptions public function Helper function to get the options of given style name.
StylePluginBase::getStyleOptionsCount public function Helper function to get the options of given style name.
StylePluginBase::getTitle public function Return the name of the Styles Group form plugin. Overrides StylePluginInterface::getTitle
StylePluginBase::validateConfigurationForm public function
StylePluginBase::__construct public function Constructs a StylePluginBase object. Overrides PluginBase::__construct 1
TextColor::build public function Overrides StylePluginBase::build
TextColor::buildConfigurationForm public function Overrides StylePluginBase::buildConfigurationForm
TextColor::buildStyleFormElements public function Overrides StylePluginBase::buildStyleFormElements
TextColor::submitConfigurationForm public function Overrides StylePluginBase::submitConfigurationForm
TextColor::submitStyleFormElements public function Overrides StylePluginBase::submitStyleFormElements