Commit ecbb3a1d authored by Rakhi Soni's avatar Rakhi Soni Committed by Ilcho Vuchkov
Browse files

Issue #3291407 by himanshu_jhaloya, Rakhi Soni, vuil: Drupal Coding Standard...

Issue #3291407 by himanshu_jhaloya, Rakhi Soni, vuil: Drupal Coding Standard Fixes As Per phpcs --standard = Drupal
parent a92b35bd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
namespace Drupal\taxonomy_import\Controller;

/**
 * Contains \Drupal\taxonomy_import\Controller\ImporttaxonomyController.
 * Class for Import Taxonomy.
 */
class ImporttaxonomyController {

+24 −17
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Contribute form.
@@ -32,7 +33,6 @@ class ImportForm extends FormBase {
  /**
   * {@inheritdoc}
   */

  public static function create(ContainerInterface $container) {
    return new static($container->get('config.factory'));
  }
@@ -44,6 +44,7 @@ class ImportForm extends FormBase {
    return 'import_taxonomy_form';
  }

  use StringTranslationTrait;
  /**
   * {@inheritdoc}
   */
@@ -60,7 +61,7 @@ class ImportForm extends FormBase {
      '#attributes' => [
        'class' => ['vocab-name-select'],
      ],
      '#description' => t('Select vocabulary!'),
      '#description' => $this->t('Select vocabulary!'),
    ];
    $form['taxonomy_file'] = [
      '#type' => 'managed_file',
@@ -143,8 +144,9 @@ function create_taxonomy($voc_name) {
      while (($data = fgetcsv($handle)) !== FALSE) {
        $termid = 0;
        $term_id = 0;
        // Get tid of term with same name
        $termid = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid', [':uid' => $data[0], ':vid' => $vid]);
        // Get tid of term with same name.
        $termid = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid',
                  [':uid' => $data[0], ':vid' => $vid]);
        foreach ($termid as $val) {
          // Get tid.
          $term_id = $val->tid;
@@ -152,7 +154,8 @@ function create_taxonomy($voc_name) {
        // Finding parent of new item.
        $parent = 0;
        if (!empty($data[1])) {
          $parent_id = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid', [':uid' => $data[1], ':vid' => $vid]);
          $parent_id = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid',
                       [':uid' => $data[1], ':vid' => $vid]);

          foreach ($parent_id as $val) {
            if (!empty($val)) {
@@ -164,7 +167,7 @@ function create_taxonomy($voc_name) {
            }
          }
        }
        $target_term = null;
        $target_term = NULL;
        // Check whether term already exists or not.
        if (empty($term_id)) {
          // Create  new term.
@@ -195,11 +198,11 @@ function create_taxonomy($voc_name) {
        }
        if (count($data1) > 2 && !empty($target_term)) {
          $i = 2;
          $update = false;
          $update = FALSE;
          while ($i < count($data1)) {
            if (!empty($data[$i]) && !empty($data1[$i])) {
              $target_term->set($data1[$i], $data[$i]);
              $update = true;
              $update = TRUE;
            }
            $i++;
          }
@@ -211,7 +214,8 @@ function create_taxonomy($voc_name) {
      fclose($handle);
      // Redirecting to taxonomy term overview page.
      $url = $base_url . "/admin/structure/taxonomy/manage/" . $vid . "/overview";
      header('Location:' . $url);exit;
      header('Location:' . $url);
      exit;
    }
    else {
      \Drupal::messenger()->addStatus('File contains no data');
@@ -250,7 +254,8 @@ function create_taxonomy($voc_name) {
          // Checks if parent tag exists.
          if (isset($parents) && !empty($parents)) {
            $data = $parents;
            $parent_id = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid', [':uid' => $data, ':vid' => $vid]);
            $parent_id = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid',
                         [':uid' => $data, ':vid' => $vid]);
            foreach ($parent_id as $val) {
              if (!empty($val)) {
                // Get tid.
@@ -261,7 +266,8 @@ function create_taxonomy($voc_name) {
              }
            }
          }
          $termid = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid', [':uid' => $terms, ':vid' => $vid]);
          $termid = Database::getConnection()->query('SELECT n.tid FROM {taxonomy_term_field_data} n WHERE n.name  = :uid AND n.vid  = :vid',
                    [':uid' => $terms, ':vid' => $vid]);
          foreach ($termid as $val) {
            // Get tid.
            $term_id = $val->tid;
@@ -285,7 +291,8 @@ function create_taxonomy($voc_name) {
        }
        // Redirecting to taxonomy term overview page.
        $url = $base_url . "/admin/structure/taxonomy/manage/" . $vid . "/overview";
        header('Location:' . $url);exit;
        header('Location:' . $url);
        exit;
      }
      else {
        \Drupal::messenger()->addStatus('File contains no data');
+3 −2
Original line number Diff line number Diff line
@@ -10,8 +10,9 @@
 */
function taxonomy_import_uninstall() {
  // Delete file on uninstall.
  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
  // @todo Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()`.
  // if you do not yet have access tothe container here.
  $files = \Drupal::database()->query('SELECT f.fid FROM {file_managed} f WHERE f.uri LIKE :fid', [':fid' => 'public://taxonomy_files/%']);

  $location = [];