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

dcat.module
<?php

/**
 * @file
 * Contains dcat.module..
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_help().
 */
function dcat_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the dcat module.
    case 'help.page.dcat':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Provides the different classes of DCAT as entities (Curently only Dataset, Distribution and Catalog)') . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\taxonomy\VocabularyForm.
 */
function dcat_form_taxonomy_vocabulary_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $vocabulary = $form_state->getFormObject()->getEntity();
  if (in_array($vocabulary->id(), ['dataset_keyword', 'dataset_theme'])) {
    $form['help_dcat_vocab'] = [
      '#markup' => t('This is the designated DCAT vocabulary. Some of the normal vocabulary options have been removed.'),
      '#weight' => -1,
    ];
    // Do not allow to delete dcat's vocabulary.
    $form['actions']['delete']['#access'] = FALSE;
    // Do not allow to change a vid of dcat's vocabulary.
    $form['vid']['#disabled'] = TRUE;
  }
}

/**
 * Implements hook_theme().
 */
function dcat_theme() {
  $theme = [];
  $theme['dcat_vcard'] = [
    'render element' => 'elements',
    'file' => 'dcat_vcard.page.inc',
    'template' => 'templates/dcat_vcard',
    'path' => drupal_get_path('module', 'dcat') . '/src',
  ];
  $theme['dcat_vcard_content_add_list'] = [
    'render element' => 'content',
    'variables' => ['content' => NULL],
    'file' => 'dcat_vcard.page.inc',
    'path' => drupal_get_path('module', 'dcat') . '/src',
  ];
  return $theme;
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function dcat_theme_suggestions_dcat_vcard(array $variables) {
  $suggestions = [];
  $entity = $variables['elements']['#dcat_vcard'];
  $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');

  $suggestions[] = 'dcat_vcard__' . $sanitized_view_mode;
  $suggestions[] = 'dcat_vcard__' . $entity->bundle();
  $suggestions[] = 'dcat_vcard__' . $entity->bundle() . '__' . $sanitized_view_mode;
  $suggestions[] = 'dcat_vcard__' . $entity->id();
  $suggestions[] = 'dcat_vcard__' . $entity->id() . '__' . $sanitized_view_mode;
  return $suggestions;
}

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

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