layoutcomponents-8.x-1.14-beta2/modules/lc_simple_image_with_hover_text/lc_simple_image_with_hover_text.module

modules/lc_simple_image_with_hover_text/lc_simple_image_with_hover_text.module
<?php

/**
 * @file
 * LC Simple image with hover textt file.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_theme().
 */
function lc_simple_image_with_hover_text_theme($existing, $type, $theme, $path) {
  return [
    'layoutcomponents_block_content__simple_image_with_hover_text' => [
      'base hook' => 'block',
    ],
  ];
}

/**
 * Implements hook_help().
 */
function lc_simple_image_with_hover_text_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Create help page.
    case 'help.page.lc_simple_image_with_hover_text':
      $module_handler = \Drupal::service('module_handler');
      $module_path = $module_handler->getModule('lc_simple_image_with_hover_text')->getPath();
      $file = $module_path . '/README.md';
      if (!file_exists($file)) {
        return '';
      }

      // Get content from file.
      $reader = file_get_contents($file);

      // Return "clean" content.
      return preg_replace("/\r\n|\n|\r/", "<br>", $reader);
  }
}

/**
 * Implements hook_preprocess_HOOK().
 */
function lc_simple_image_with_hover_text_preprocess_block(&$variables) {
  if (!array_key_exists('#block_content', $variables['content'])) {
    return;
  }

  /** @var \Drupal\block_content\Entity\BlockContent $block */
  $block = $variables['content']['#block_content'];

  if ($block->bundle() != 'simple_image_with_hover_text') {
    return;
  }

  $block_id = str_replace(' ', '_', $block->uuid());
  $extra_class = $block->get('field_siwht_extra_classes')->getString();
  $extra_attributes = $block->get('field_siwht_extra_attributes')->getString();

  $classes = [
    'simple-image-with-hover-text',
    'lc-inline_block_' . $block_id . '-image-with-hover-text-edit',
  ];

  // Set classes.
  if (!empty($extra_class)) {
    $extra_class = explode(" ", $extra_class);
    $classes = array_merge($classes, $extra_class);
    $variables['content']['#attributes']['class'][] = implode(" ", $classes);
  }

  // Set attributes.
  if (!empty($extra_attributes)) {
    $parts = explode(" ", $extra_attributes);
    foreach ($parts as $attribute) {
      if (strpos($attribute, '|') !== FALSE) {
        list($key, $value) = explode('|', $attribute);
        $variables['content']['#attributes'][$key] = $value;
      }
    }
  }

  $variables['#attached']['library'][] = 'lc_simple_image_with_hover_text/lc_simple_image_with_hover_text';
}

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

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