crossword-8.x-1.x-dev/crossword.module

crossword.module
<?php

/**
 * @file
 * Register some themes and theme suggestions for the crossword module.
 */

use Drupal\Core\Field\FieldTypeCategoryManagerInterface;

/**
 * Implements hook_theme().
 */
function crossword_theme($existing, $type, $theme, $path) {
  return [
    'crossword' => [
      'variables' => [
        'content' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
        'attributes' => [],
      ],
    ],
    'crossword_controls' => [
      'variables' => [
        'content' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
        'attributes' => [],
      ],
    ],
    'crossword_grid' => [
      'variables' => [
        'content' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
        'attributes' => [],
      ],
    ],
    'crossword_grid_row' => [
      'variables' => [
        'content' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
        'attributes' => [],
      ],
    ],
    'crossword_square' => [
      'variables' => [
        'fill' => NULL,
        'numeral' => NULL,
        'image' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
        'attributes' => [],
      ],
    ],
    'crossword_clue' => [
      'variables' => [
        'text' => NULL,
        'numeral' => NULL,
        'direction' => NULL,
        'direction_label' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
        'attributes' => [],
      ],
    ],
    'crossword_clues' => [
      'variables' => [
        'content' => NULL,
        'direction' => NULL,
        'direction_label' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
        'attributes' => [],
      ],
    ],
    'crossword_instructions' => [
      'variables' => [
        'field_formatter' => NULL,
        'cheat' => TRUE,
        'rebus' => TRUE,
        'errors' => TRUE,
      ],
    ],
    'crossword_active_clues' => [
      'variables' => [
        'congrats' => NULL,
        'pseudofield' => FALSE,
        'field_formatter' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword clues.
 *
 * Makes it easier to theme across clues and down clues separately.
 */
function crossword_theme_suggestions_crossword_clues_alter(array &$suggestions, array $variables) {
  $suggestions[] = 'crossword_clues__' . $variables['direction'];
  if ($variables['pseudofield']) {
    $suggestions[] = 'crossword_clues__pseudofield';
    $suggestions[] = 'crossword_clues__pseudofield__' . $variables['direction'];
  }
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_clues__' . $variables['field_formatter'];
    $suggestions[] = 'crossword_clues__' . $variables['field_formatter'] . '__' . $variables['direction'];
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword clue.
 */
function crossword_theme_suggestions_crossword_clue_alter(array &$suggestions, array $variables) {
  $suggestions[] = 'crossword_clue__' . $variables['direction'];
  if ($variables['pseudofield']) {
    $suggestions[] = 'crossword_clue__pseudofield';
    $suggestions[] = 'crossword_clue__pseudofield__' . $variables['direction'];
  }
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_clue__' . $variables['field_formatter'];
    $suggestions[] = 'crossword_clue__' . $variables['field_formatter'] . '__' . $variables['direction'];
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword controls.
 */
function crossword_theme_suggestions_crossword_controls_alter(array &$suggestions, array $variables) {
  if ($variables['pseudofield']) {
    $suggestions[] = 'crossword_controls__pseudofield';
  }
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_controls__' . $variables['field_formatter'];
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword square.
 */
function crossword_theme_suggestions_crossword_square_alter(array &$suggestions, array $variables) {
  if ($variables['pseudofield']) {
    $suggestions[] = 'crossword_square__pseudofield';
  }
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_square__' . $variables['field_formatter'];
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword grid.
 */
function crossword_theme_suggestions_crossword_grid_alter(array &$suggestions, array $variables) {
  if ($variables['pseudofield']) {
    $suggestions[] = 'crossword_grid__pseudofield';
  }
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_grid__' . $variables['field_formatter'];
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword grid row.
 */
function crossword_theme_suggestions_crossword_grid_row_alter(array &$suggestions, array $variables) {
  if ($variables['pseudofield']) {
    $suggestions[] = 'crossword_grid_row__pseudofield';
  }
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_grid_row__' . $variables['field_formatter'];
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword active clues.
 */
function crossword_theme_suggestions_crossword_active_clues_alter(array &$suggestions, array $variables) {
  if ($variables['pseudofield']) {
    $suggestions[] = 'crossword_active_clues__pseudofield';
  }
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_active_clues__' . $variables['field_formatter'];
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword.
 */
function crossword_theme_suggestions_crossword_alter(array &$suggestions, array $variables) {
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword__' . $variables['field_formatter'];
    // This next thing is for maintaining BC.
    if ($variables['field_formatter'] == 'crossword_solution') {
      $suggestions[] = 'crossword_solution';
    }
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter() for crossword instructions.
 */
function crossword_theme_suggestions_crossword_instructions_alter(array &$suggestions, array $variables) {
  if ($variables['field_formatter']) {
    $suggestions[] = 'crossword_instructions__' . $variables['field_formatter'];
  }
}

/**
 * Implements hook_field_type_category_info_alter().
 */
function crossword_field_type_category_info_alter(&$definitions) {
  // The `crossword` field type belongs in the `general` category, so the libraries
  // need to be attached using an alter hook.
  $definitions[FieldTypeCategoryManagerInterface::FALLBACK_CATEGORY]['libraries'][] = 'crossword/crossword.crossword-icon';
}

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

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