You are here

public function Element::setButtonSize in Express 8

Adds Bootstrap button size class to the element.

Parameters

string $class: The full button size class to add. If none is provided, it will default to any set theme setting.

bool $override: Flag indicating if the passed $class should be forcibly set. Setting this to FALSE allows any existing set class to persist.

Return value

$this

File

themes/contrib/bootstrap/src/Utility/Element.php, line 585
Contains \Drupal\bootstrap\Utility\Element.

Class

Element
Provides helper methods for Drupal render elements.

Namespace

Drupal\bootstrap\Utility

Code

public function setButtonSize($class = NULL, $override = TRUE) {

  // Immediately return if element is not a button.
  if (!$this
    ->isButton()) {
    return $this;
  }

  // Retrieve the button size classes from the specific setting's options.
  static $classes;
  if (!isset($classes)) {
    $classes = [];
    if ($button_size = Bootstrap::getTheme()
      ->getSettingPlugin('button_size')) {
      $classes = array_keys($button_size
        ->getOptions());
    }
  }

  // Search for an existing class.
  if (!$class || !$override) {
    foreach ($classes as $value) {
      if ($this
        ->hasClass($value)) {
        $class = $value;
        break;
      }
    }
  }

  // Attempt to get the default button size, if set.
  if (!$class) {
    $class = Bootstrap::getTheme()
      ->getSetting('button_size');
  }

  // Remove any existing classes and add the specified class.
  if ($class) {
    $this
      ->removeClass($classes)
      ->addClass($class);
    if ($this
      ->getProperty('split')) {
      $this
        ->removeClass($classes, $this::SPLIT_BUTTON)
        ->addClass($class, $this::SPLIT_BUTTON);
    }
  }
  return $this;
}