You are here

public function StyleBase::getSelector in GridStack 8.2

Returns selectors and sub-selectors with context related to box levels.

2 calls to StyleBase::getSelector()
Background::getBackgroundColor in src/Plugin/gridstack/stylizer/Background.php
Returns the background colors grouped by the given key, w/o text colors.
Color::getTextColor in src/Plugin/gridstack/stylizer/Color.php
Returns the text colors grouped by the given key.

File

src/Plugin/gridstack/stylizer/StyleBase.php, line 48

Class

StyleBase
Provides the base styles.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

public function getSelector(array $settings, $key = '', array $rules = []) {
  $sub = '';
  $selector = $settings['_selector'];
  $index = isset($settings['delta']) ? $settings['delta'] + 1 : 0;
  $overlay = $this
    ->getStyle('overlay', $settings);
  $rid = empty($settings['rid']) ? '' : $settings['rid'];
  $suffix = str_replace([
    'gridstack_',
    ':root',
  ], '', $rid);
  $suffix = str_replace('_', '-', $suffix);
  switch ($settings['_level']) {
    case GridStackDefault::LEVEL_ROOT:
      $context = GridStackDefault::ROOT;
      $suffix = 0;
      break;
    case GridStackDefault::LEVEL_ROOT_ITEM:
      $context = $index;
      $selector = $selector . ' .box--' . $index;
      $sub = '.box__content';
      break;
    case GridStackDefault::LEVEL_NESTED:
      $context = GridStackDefault::NESTED . $index;
      $selector = $selector . ' .gridstack--' . $index;
      break;
    case GridStackDefault::LEVEL_NESTED_ITEM:
      $context = $settings['nested_id'];
      $selector = $selector . ' .box--' . $context;
      $sub = '.box__content';
      break;
    default:
      break;
  }
  $main_selector = $sub ? $selector . ' ' . $sub : $selector;

  // @todo $bg_selector = $overlay ? $selector . ' .b-gs--' . $suffix . ' .media__overlay' : $main_selector;
  $bg_selector = $overlay ? $selector . ' .b-gs .media__overlay' : $main_selector;
  $rules = $rules ? array_unique($rules) : [];
  $data = [
    'index' => $index,
    'level' => $settings['_level'],
    'context' => $context,
    'selector' => $main_selector,
    'bg_selector' => $bg_selector,
    'overlay' => $overlay,
    'rid' => $rid,
    'suffix' => $suffix,
    'sub' => $sub,
    'rules' => $rules,
  ];
  if ($key) {
    return isset($data[$key]) ? $data[$key] : FALSE;
  }
  return $data;
}