public function Breadcrumb::buildConfigurationForm in Context Breadcrumb 8
File
- src/
Plugin/ ContextReaction/ Breadcrumb.php, line 48
Class
- Breadcrumb
- Provides a content reaction that adds breadcrumb to page.
Namespace
Drupal\context_breadcrumb\Plugin\ContextReactionCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$breadcrumbs = $this
->getConfiguration()['breadcrumbs'];
$form['breadcrumbs'] = [
'#type' => 'table',
'#header' => [
$this
->t('Title'),
$this
->t('Url'),
$this
->t('Token'),
],
'#rows' => [],
];
for ($i = 0; $i <= 8; $i++) {
$form['breadcrumbs'][$i]['title'] = [
'#type' => 'textarea',
'#title' => $this
->t('Title'),
'#rows' => 1,
'#title_display' => 'invisible',
'#default_value' => !empty($breadcrumbs[$i]['title']) ? $breadcrumbs[$i]['title'] : '',
];
$form['breadcrumbs'][$i]['url'] = [
'#type' => 'textarea',
'#title' => $this
->t('URL'),
'#rows' => 1,
'#title_display' => 'invisible',
'#default_value' => !empty($breadcrumbs[$i]['url']) ? $breadcrumbs[$i]['url'] : '',
];
$form['breadcrumbs'][$i]['token'] = [
'#type' => 'select',
'#required' => FALSE,
'#title' => $this
->t('Token'),
'#title_display' => 'invisible',
'#default_value' => !empty($breadcrumbs[$i]['token']) ? 1 : '',
'#empty_value' => '',
'#options' => [
'' => $this
->t('None'),
1 => $this
->t('Yes'),
],
];
}
if (\Drupal::service('module_handler')
->moduleExists("token")) {
$token_tree = [
'#theme' => 'token_tree_link',
'#token_types' => [
'node',
'user',
'term',
'vocabulary',
],
];
$rendered_token_tree = \Drupal::service('renderer')
->render($token_tree);
$form['description']['#type'] = 'item';
$form['description']['#description'] = t('This field supports tokens. @browse_tokens_link', [
'@browse_tokens_link' => $rendered_token_tree,
]);
}
return $form;
}