Showing posts with label entityTypeManager. Show all posts
Showing posts with label entityTypeManager. Show all posts

Tuesday 19 March 2019

How to get the Parent id from term id in drupal 8?

It's easy way to tackle this problem, Sometimes we face this issue and take the query help and get the parent id, but we have here solution for this issue.

Just write the loadParent syntax as per given instructions:

Syntax:

$term_id = $node->get('field_category')->target_id;
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($term_id);
$parentids = $term->parent->target_id;

OR

 $parent = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadParents($term_id);   // here term_id is child term id
 $parent = reset($parent); //reset the parent array
 $parentids = $parent->id();    //get the parent id  


Note: If have any suggestions or issue regarding 'How to get the Parent id from term id in drupal 8?' then you can ask by comments.

Thursday 9 August 2018

Vocabulary or Taxonomy load in Drupal 8.

If we have vocabulary/taxonomy name then we can easily load by loadTree, follow the syntax.

$tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('write vocabulary machine name here');
foreach ($tree as $term) {
  echo $term->tid.' - '.$term->name;
}

Example:
$select_category .= '<select><option value="0">- Select -</option>';
$tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('product_family'); //here product_family is machine name of Product Family taxonomy.
foreach ($tree as $term) {
$select_category .= '<option value="' . $parent . '_' . $term->tid . '">' . $term->name . '</option>';
}
$select_category .= '</select>';


Note: If have any suggestions or issue regarding 'Vocabulary or Taxonomy load in Drupal 8.' then you can ask by comments.

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...