trait TreeStyleTrait in Views tree 8.2
Contains common code for list and table tree style displays.
@property \Drupal\views\Plugin\views\display\DisplayPluginBase $displayHandler @property array $options
Hierarchy
- trait \Drupal\views_tree\TreeStyleTrait
2 files declare their use of TreeStyleTrait
- Tree.php in src/
Plugin/ views/ style/ Tree.php - TreeTable.php in src/
Plugin/ views/ style/ TreeTable.php
File
- src/
TreeStyleTrait.php, line 13
Namespace
Drupal\views_treeView source
trait TreeStyleTrait {
/**
* Gather common options.
*/
protected function defineCommonOptions(array &$options) {
$options['main_field'] = [
'default' => '',
];
$options['parent_field'] = [
'default' => '',
];
}
/**
* Builds common form elements for the options form.
*
* @param array $form
* The form definition.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
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."),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TreeStyleTrait:: |
protected | function | Gather common options. | |
TreeStyleTrait:: |
protected | function | Builds common form elements for the options form. |