drowl_paragraphs_bs-1.x-dev/modules/drowl_paragraphs_bs_type_button/drowl_paragraphs_bs_type_button.module

modules/drowl_paragraphs_bs_type_button/drowl_paragraphs_bs_type_button.module
<?php

/**
 * @file
 * The install file.
 */

use Drupal\Core\Template\Attribute;

/**
 * Prepared variables for paragraph output.
 */
function drowl_paragraphs_bs_type_button_preprocess_paragraph(&$variables) {
  if ($variables['paragraph']->bundle() == 'button') {
    // Get button specific ui_styles so we can apply them to
    // this the link element, instead the paragraph wrapper.
    $variables['button_attributes'] = new Attribute();
    if (isset($variables['attributes']['class'])) {
      foreach ($variables['attributes']['class'] as $class) {
        if (str_starts_with($class, 'btn-') || str_starts_with($class, 'text-')) {
          $variables['attributes']->removeClass($class);
          $variables['button_attributes']->addClass($class);
        }
        // Add the ability to add classes to the button element that do not start with
        // 'btn-' using the 'btn__' prefix, which is removed from the final classname.
        if (str_starts_with($class, 'btn__') || str_starts_with($class, 'rounded-') || str_starts_with($class, 'bg-') || str_starts_with($class, 'text-')) {
          $variables['attributes']->removeClass($class);
          $variables['button_attributes']->addClass(str_replace('btn__', '', $class));
        }
      }
    }
  }
}

/**
 * Implements hook_theme().
 */
function drowl_paragraphs_bs_type_button_theme($existing, $type, $theme, $path) {
  $templates = $path . '/templates';
  return [
    'paragraph__drowl_paragraphs_bs__button' => [
      'base hook' => 'paragraph',
      'path' => $templates,
    ],
  ];
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc