You are here

public static function GinLbExtension::ginClasses in Gin Layout Builder 1.0.x

Replaces all theme classes with gin classes.

Parameters

\Drupal\Core\Template\Attribute $attribute: Twig attributes.

Return value

\Drupal\Core\Template\Attribute The replaced attributes.

1 call to GinLbExtension::ginClasses()
GinLbExtensionTest::testGinClasses in tests/Unit/TwigExtension/GinLbExtensionTest.php
@covers ::calculateDependencies

File

src/TwigExtension/GinLbExtension.php, line 56

Class

GinLbExtension
A class providing Gin Twig function.

Namespace

Drupal\gin_lb\TwigExtension

Code

public static function ginClasses(Attribute $attribute) {
  $gin_lb_classes = self::getGinLbClasses();
  if ($attribute
    ->getClass() === NULL) {
    return $attribute;
  }
  $renamed_classes = [];

  // These classes need to be kept for script purposes.
  // If this class has been styled, then we'll keep both classes: the original
  // and the custom glb one.
  $script_classes = [
    'form-autocomplete',
  ];
  foreach ($attribute
    ->getClass() as $class_string) {

    // $attribute->getClass returns multiple classes as one class.
    // To prefix this classes - explode it.
    $classes = explode(' ', $class_string);
    foreach ($classes as $class) {
      if (in_array('glb-' . $class, $gin_lb_classes)) {
        $renamed_classes[] = 'glb-' . $class;
        if (in_array($class, $script_classes)) {
          $renamed_classes[] = $class;
        }
      }
      else {
        $renamed_classes[] = $class;
      }
    }
  }
  $attribute
    ->setAttribute('class', $renamed_classes);
  return $attribute;
}