This module provides a widget dedicated for taxonomy term reference field. It displays the terms list with an OptGroup format.All the nested level terms are also grouped under the main parent term.

The <optgroup> tag is used to group related options in a <select> element (drop-down list).

If you have a long list of options, groups of related options are easier to handle for a user.

Project link

https://www.drupal.org/project/optgroup_taxonomy_select

Git instructions

git clone --branch 8.1.x https://git.drupalcode.org/project/optgroup_taxonomy_select.git

PAReview checklist

https://pareview.sh/pareview/https-git.drupal.org-project-optgroup_taxon...

Comments

Swetha_Bapanah created an issue. See original summary.

swetha_bapanah’s picture

Status: Active » Needs review

Hi Team,

Request you to review this module.

Thanks,
Swetha

gaurav_drupal’s picture

Status: Needs review » Needs work

Swetha_Bapanah Thanks for your contribution.

Can you please check this code at line 39 of modules/contrib/optgroup_taxonomy_select/src/Plugin/Field/FieldWidget/OptgroupTermSelectWidget.php

$result[$parent][$item->tid] = $item->name;

It looks like the $parent variable is undefined. You might want to initialize it.

elavarasan r’s picture

@Swetha_Bapanah,

Thanks for your contribution.

Use dependency injection instead of calling directly \Drupal::entityTypeManager() in the class file.

Use "entity_type.manager" service and inject this service into OptionsWidgetBase class.

avpaderno’s picture

swetha_bapanah’s picture

Status: Needs work » Needs review

Hi Team,

Have made all the changes as per the review comments, please review. Have created the new tag 8.x-1.2.

Thanks,
Swetha

elavarasan r’s picture

Status: Needs review » Needs work

Thanks for the update.
Some variables are useless in the construct section

public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
    $this->entityTypeManager = $entity_type_manager;
} 

Instead, Please add the below code

/**
   * Constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The config service.   
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

and same issue on create function also, please update with the below,

public static function create(ContainerInterface $container) {
    return new static(     
      $container->get('entity_type.manager')
    );
  }

and remove unnecessary classes from the use section.

Once committed the code into branch, Please check for any coding standard issues by Pareview url.

Don't create a new tag for each update. Please use the same branch and push the code into same branch.
Reviewer will refer the code from the current default branch. In your case the branch is 8.x-1.x. Once it is stable, then create new tag.

rohitrajputsahab’s picture

@Swetha_Bapanah
I'm not able to add value. Can you please check this and i have attached screenshot for your reference.

avpaderno’s picture

The following code is correct.

public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
    $this->entityTypeManager = $entity_type_manager;
}

It's calling the parent constructor method, which is expecting those values.

elavarasan r’s picture

@kiamlaluno, You are correct.

@Swetha_Bapanah

You don't need to implement the code that i have mentioned above.

swetha_bapanah’s picture

Status: Needs work » Needs review

Hi @rohit-rajput-sahab,

Looks like there are no terms added in the vocabulary you selected for the particular field and now I have updated with the empty label option. The latest code is pushed to 8.1.x branch, please review and confirm. If no issues, I will create the tag later.

Thanks,
Swetha

shaktik’s picture

Hi @Swetha_Bapanah,

Kindly check below errors.

2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

------ -----------------------------------------------------------------------
Line src/Plugin/Field/FieldWidget/OptgroupTermSelectWidget.php
------ -----------------------------------------------------------------------
87 Access to an undefined property
Drupal\optgroup_taxonomy_select\Plugin\Field\FieldWidget\OptgroupTerm
SelectWidget::$multiple.
87 Access to an undefined property
Drupal\optgroup_taxonomy_select\Plugin\Field\FieldWidget\OptgroupTerm
SelectWidget::$options.
96 Access to an undefined property
Drupal\optgroup_taxonomy_select\Plugin\Field\FieldWidget\OptgroupTerm
SelectWidget::$multiple.
96 Method
Drupal\optgroup_taxonomy_select\Plugin\Field\FieldWidget\OptgroupTerm
SelectWidget::getEmptyLabel() should return string|null but return
statement is missing.
98 Access to an undefined property
Drupal\optgroup_taxonomy_select\Plugin\Field\FieldWidget\OptgroupTerm
SelectWidget::$required.
106 Access to an undefined property
Drupal\optgroup_taxonomy_select\Plugin\Field\FieldWidget\OptgroupTerm
SelectWidget::$required.
109 Access to an undefined property
Drupal\optgroup_taxonomy_select\Plugin\Field\FieldWidget\OptgroupTerm
SelectWidget::$has_value.
------ -----------------------------------------------------------------------

[ERROR] Found 7 errors

rohitrajputsahab’s picture

Hi @Swetha_Bapanah,

In my vocabulary, there are around 300 terms. Please see screenshot.

rohitrajputsahab’s picture

Status: Needs review » Needs work
avpaderno’s picture

Priority: Normal » Minor
avpaderno’s picture

Status: Needs work » Closed (won't fix)

I am closing this application due to lack of replies.