TreeStyleTrait.php in Views tree 8.2
File
src/TreeStyleTrait.php
View source
<?php
namespace Drupal\views_tree;
use Drupal\Core\Form\FormStateInterface;
trait TreeStyleTrait {
protected function defineCommonOptions(array &$options) {
$options['main_field'] = [
'default' => '',
];
$options['parent_field'] = [
'default' => '',
];
}
protected function getCommonOptionsForm(array &$form, FormStateInterface $form_state) {
$fields = [
'' => $this
->t('<None>'),
];
foreach ($this->displayHandler
->getHandlers('field') as $field => $handler) {
$fields[$field] = $handler
->adminLabel();
}
$form['main_field'] = [
'#type' => 'select',
'#title' => $this
->t('Main field'),
'#options' => $fields,
'#default_value' => $this->options['main_field'],
'#description' => $this
->t('Select the field with the unique identifier for each record.'),
'#required' => TRUE,
];
$form['parent_field'] = [
'#type' => 'select',
'#title' => $this
->t('Parent field'),
'#options' => $fields,
'#default_value' => $this->options['parent_field'],
'#description' => $this
->t("Select the field that contains the unique identifier of the record's parent."),
];
}
}
Traits
Name |
Description |
TreeStyleTrait |
Contains common code for list and table tree style displays. |