You are here

protected function Background::getBackgroundColor in GridStack 8.2

Returns the background colors grouped by the given key, w/o text colors.

2 calls to Background::getBackgroundColor()
Media::prepareOverlay in src/Plugin/gridstack/stylizer/Media.php
Returns the media overlay.
Style::getStyles in src/Plugin/gridstack/stylizer/Style.php
Parses the given color strings keyed by index or .box__content or selector.

File

src/Plugin/gridstack/stylizer/Background.php, line 18

Class

Background
Provides the background color styles.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function getBackgroundColor(array $settings, $with_text = TRUE) {
  $build = [];
  if ($this
    ->getColors($settings)) {
    $rgb = 'bg';
    $rgba = 'rgba';
    $text = 'text';
    $data = $this
      ->getSelector($settings);
    $key = isset($data['selector']) ? $data['selector'] : '';
    $bg_key = isset($data['bg_selector']) ? $data['bg_selector'] : '';

    // Background color and text color have the same selector, hence grouped.
    if ($key && ($this
      ->getColor($rgba, $settings) || $this
      ->getColor($rgb, $settings) || $this
      ->getColor($text, $settings))) {
      $bg = $this
        ->getColor($rgb, $settings) ?: '';
      $bg = $this
        ->getColor($rgba, $settings) ?: $bg;
      $text = $this
        ->getColor($text, $settings) ?: '';
      $bg = $bg ? 'background-color:' . $bg . ';' : '';
      $text = $text ? 'color:' . $text . ';' : '';
      if ($data['overlay']) {
        if ($text && $with_text) {
          $build[$key] = $text;
        }
        if ($bg) {
          $build[$bg_key] = $bg;
        }
      }
      else {
        if ($bg || $text) {
          $build[$key] = $with_text ? $bg . $text : $bg;
        }
      }
    }
    $build = array_unique($build);
  }
  return $build;
}