You are here

public function OpignoActivityForm::_getSkillsFromTree in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Form/OpignoActivityForm.php \Drupal\opigno_module\Form\OpignoActivityForm::_getSkillsFromTree()

Get needed skills by target skill.

1 call to OpignoActivityForm::_getSkillsFromTree()
OpignoActivityForm::buildForm in src/Form/OpignoActivityForm.php
Form constructor.

File

src/Form/OpignoActivityForm.php, line 211

Class

OpignoActivityForm
Form controller for Activity edit forms.

Namespace

Drupal\opigno_module\Form

Code

public function _getSkillsFromTree($target_skill, array $term_options) {
  $term_storage = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term');
  $skills_from_tree = $term_storage
    ->loadTree('skills', $target_skill);
  $options = [];
  foreach ($skills_from_tree as $row) {
    $options[$row->tid] = $row->name;
  }
  foreach ($term_options as $key => $option) {
    if (array_key_exists($key, $options)) {
      $term_options[$key] = $options[$key];
    }
    elseif ($key != '_none') {
      unset($term_options[$key]);
    }
  }
  return $term_options;
}