You are here

taxonomy_import.module in Taxonomy Import 2.x

Same filename and directory in other branches
  1. 8 taxonomy_import.module

This module allows create taxonomy.

File

taxonomy_import.module
View source
<?php

/**
 * @file
 * This module allows create taxonomy.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Function implements hook_preprocess_page().
 */
function taxonomy_import_preprocess_page(&$variables) {
  $variables['page']['#cache']['contexts'][] = 'route';
  $route_b = \Drupal::routeMatch()
    ->getRouteName();

  // For custom form.
  if ($route_b == 'taxonomy_import.settings') {
    $variables['#attached']['library'][] = 'taxonomy_import/common-styling';
  }
}

/**
 * Implements hook_help().
 */
function taxonomy_import_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.taxonomy_import':
      global $base_url;
      $sample_csv = $base_url . '/' . drupal_get_path('module', 'taxonomy_import') . '/CSV_Test.csv';
      $sample_xml = $base_url . '/' . drupal_get_path('module', 'taxonomy_import') . '/XML_Test.xml';
      $output = '<h3>' . t('Introduction') . '</h3>';
      $output .= '<p>' . t('This module can be used to create taxonomy terms by importing data from
      CSV or XML file to a specified Vocabulary.') . '</p>';
      $output .= '<dl>';
      $output .= '<h3>' . t('Requirements') . '</h3>';
      $output .= '<p>' . t('This module requires the following: A CSV or XML file of Taxonomy terms
      to import. The .csv file can have two or more columns,eg:- name, parent. The first column is
      taken as Name and second column is taken as Parent of the Taxonomy Term created. The first row
      will be the headers. The .xml file can have two tags, eg:- name, parent. Refer the example
      given in the module folder XML_Test.xml, CSV_Test.csv.') . '</p>';
      $output .= '<h3>' . t('Installation') . '</h3>';
      $output .= '<p>' . t('Install as usual, see https://www.drupal.org/docs/8/extending-drupal-8/
       for further information.') . '</p>';
      $output .= '<h3>' . t('Configuration') . '</h3>';
      $output .= '<p>' . t('After successfully installing the module taxonomy_import, you can create
      a vocabulary and save terms to it provided via the file import. Install the module
      taxonomy_import. Go to Configuration and select Taxonomy Import from Content Authoring. It
      will redirect you to Taxonomy Import Form, with two fields: Vocabulary name and Import file.') . '</p>';
      $output .= '<p>' . t('For a Taxonomy term, the two main fields are its Name and Relations.
      Before selecting the file, you need to consider that this module create taxonomy terms with a
      name and a parent. So these data should come first in your file. Give values to the fields.
      The file Imported should be a CSV or XML.') . '</p>';
      $output .= '<p>' . t('Click on Import which redirects you to admin/structure/taxonomy/manage/
      vocabulary name/overview page. If .csv file contains two colums, the first column value is
      set as Name and second column value is set as Parent. For creating hierarchy based taxonomy,
      the values in the second column should come in the first column at the beginning of the file.
      Similarly .xml file can have two or more tags with values from which first value will be saved
      to Name and second value will be saved to Parent fields of taxonomy respectively.
      You can reuse the Vocabulary name to import taxonomy terms again.') . '</p>';
      $output .= '<h3>' . t('Sample Files') . '</h3>';
      $output .= '<p><ul><li><b><a href="' . $sample_csv . '" title="Sample CSV File">CSV</a></b></li>
      <li><b><a href="' . $sample_xml . '" title="Sample XML File">XML</a></b></li></ul></p>';
      $output .= '<h3>' . t('Maintainers') . '</h3>';
      $output .= '<p><ul><li>Sajini Antony</li><li>Neethu P S</li></ul></p>';
      return $output;
    default:
  }
}

Functions

Namesort descending Description
taxonomy_import_help Implements hook_help().
taxonomy_import_preprocess_page Function implements hook_preprocess_page().