You are here

private function CategorizedOptionsbuttonsWidget::getTaxonomyChildren in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  2. 8.3 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  3. 8.4 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  4. 8.5 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  5. 8.6 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  6. 8.7 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  7. 8.8 modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  8. 10.3.x modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  9. 10.0.x modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
  10. 10.2.x modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php \Drupal\social_profile\Plugin\Field\FieldWidget\CategorizedOptionsbuttonsWidget::getTaxonomyChildren()

Reaches into all children and flattens the taxonomy.

This method is private for a reason. We don't handle extra nesting yet but could want to do this in the future. Do not rely on this method existing in the future.

Parameters

array $parent: The parent whose children to recurse through.

int $hyphens: The number of hyphens to use as a label prefix.

Return value

array[] A flattened array of children.

1 call to CategorizedOptionsbuttonsWidget::getTaxonomyChildren()
CategorizedOptionsbuttonsWidget::formElement in modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php
Returns the form for a single field widget.

File

modules/social_features/social_profile/src/Plugin/Field/FieldWidget/CategorizedOptionsbuttonsWidget.php, line 185

Class

CategorizedOptionsbuttonsWidget
Plugin implementation of the 'categorized_options_buttons' widget.

Namespace

Drupal\social_profile\Plugin\Field\FieldWidget

Code

private function getTaxonomyChildren(array $parent, $hyphens = 0) {
  $children = [];
  $selected = [];
  foreach ($parent['children'] as $tid => $child) {
    $children[$tid] = str_repeat('-', $hyphens) . $child['label'];
    if ($child['selected']) {
      $selected[] = $tid;
    }
    if (!empty($child['children'])) {
      $result = $this
        ->getTaxonomyChildren($child, $hyphens + 1);
      $children += $result['children'];
      $selected += $result['selected'];
    }
  }
  return [
    'children' => $children,
    'selected' => $selected,
  ];
}