public function TaxoAdminForm::buildForm in Taxonomy Facets 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ TaxoAdminForm.php, line 32 - Contains Drupal\taxonomy_facets\Form\TaxoAdminForm.
Class
Namespace
Drupal\taxonomy_facets\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('taxonomy_facets.settings');
$form['page_title'] = [
'#type' => 'textfield',
'#size' => 20,
'#title' => $this
->t('Page title'),
'#description' => $this
->t('Optionaly set the title of the node listing page'),
'#default_value' => $config
->get('page_title'),
];
$form['number_of_nodes_per_page'] = [
'#type' => 'textfield',
'#size' => 4,
'#title' => $this
->t('Number of nodes per page'),
'#description' => $this
->t('Maximum number of nodes on a listing page, pager will be displayed at the bottom so user can view more nodes'),
'#default_value' => $config
->get('number_of_nodes_per_page'),
];
$form['show_nodes_if_no_filters'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show all nodes if no filters applied'),
'#description' => $this
->t('When user first lands on listing page, and no filters are applied, you can choose to show all node, or none.
To show none deselect this check box'),
'#default_value' => $config
->get('show_nodes_if_no_filters'),
];
$form['cascade_terms'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Cascade terms'),
'#description' => $this
->t("Check this box if you want the node to appear in the result set when parent terms are selected. \n for example if node is associated with location London, but you want a node to appear in the result set if the filter applied \n is Europe, or UK, you can do it in two ways:") . "</br>" . $this
->t("1. Manually associate the node with parent terms, when you edit node select, for example, UK and Europe.\n (In which case leave all above checkboxes unchecked)") . "</br>" . $this
->t("2. Ckeck the checkbox for each Vocabulary that you want to cascade.\n Nodes will automaticaly be associated with all parent terms. Check only Vocabularies that you use for Taxo Faceted filtering") . "</br>" . $this
->t("NOTE: Thois only makes sense for Taxonomy with hierarchical values, for flat taxonomies leave these boxes unchecked") . "</br>",
);
$vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple();
foreach ($vocabularies as $vocabulary) {
$form['cascade_terms'][$vocabulary
->id()] = [
'#type' => 'checkbox',
'#title' => $vocabulary
->label(),
'#default_value' => $config
->get($vocabulary
->id()),
];
}
$contentTypes = \Drupal::service('entity.manager')
->getStorage('node_type')
->loadMultiple();
$form['node_types'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Node types'),
'#description' => $this
->t("Select which node types you want to appear on the Taxonomy Faceted listing page.") . "</br>" . $this
->t("Selected content types will appear on the listings page and will be available for filtering,\n rest of the nodes will be ignored. ") . "</br>" . $this
->t("NOTE: If you want all content types to appear in the search than leave all boxes unselected. \n This will have better performance that selecting all content types") . "</br>",
);
foreach ($contentTypes as $contentType) {
$form['node_types']['ct_' . $contentType
->id()] = [
'#type' => 'checkbox',
'#title' => $contentType
->label(),
'#default_value' => $config
->get('ct_' . $contentType
->id()),
];
}
return parent::buildForm($form, $form_state);
}