ebt_tiles-1.4.1/ebt_tiles.module

ebt_tiles.module
<?php

/**
 * @file
 * Add templates for EBT Tiles.
 */

/**
 * Implements hook_theme_registry_alter().
 */
function ebt_tiles_theme_registry_alter(&$theme_registry) {
  $ebt_module = 'ebt_tiles';
  $module_path = \Drupal::service('extension.list.module')->getPath($ebt_module);
  $base_theme = 'paragraph';
  $theme_registry['paragraph__ebt_tiles_item__default'] = [
    'path' => $module_path . '/templates',
    'template' => 'paragraph--ebt-tiles-item--default',
    'render element' => $theme_registry[$base_theme]['render element'],
    'base hook' => $base_theme,
    'type' => 'module',
    'theme path' => $module_path,
    'preprocess functions' => $theme_registry[$base_theme]['preprocess functions'],
    'initial preprocess' => 'template_preprocess_paragraph',
  ];
}

/**
 * Implements hook_preprocess_paragraph().
 */
function ebt_tiles_preprocess_paragraph(array &$variables) {
  if ($variables['paragraph']->bundle() != 'ebt_tiles_item') {
    return;
  }

  if (empty($variables['paragraph']->getParentEntity()) ||
    !$variables['paragraph']->getParentEntity()->hasField('field_ebt_settings') ||
    $variables['paragraph']->getParentEntity()->get('field_ebt_settings')->isEmpty()) {
    return;
  }

  // Get the 'field_ebt_settings' from Parent.
  $ebt_settings = $variables['paragraph']->getParentEntity()->get('field_ebt_settings')->first()->getValue();

  // Default value.
  $link_in_a_new_tab = FALSE;

  // If is configured to open in a new tab, return this in a variable.
  if (!empty($ebt_settings['ebt_settings']['links']['link_in_a_new_tab'])) {
    $link_in_a_new_tab = $ebt_settings['ebt_settings']['links']['link_in_a_new_tab'];
  }

  // Default value for "nofollow".
  $nofollow = FALSE;

  // If is configured to add "nofollow", use it.
  if (!empty($ebt_settings['ebt_settings']['links']['add_nofollow'])) {
    $nofollow = $ebt_settings['ebt_settings']['links']['add_nofollow'];
  }

  $variables['link_in_a_new_tab'] = $link_in_a_new_tab;
  $variables['nofollow'] = $nofollow;
}

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

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