class TaxoAdminForm in Taxonomy Facets 8
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\taxonomy_facets\Form\TaxoAdminForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of TaxoAdminForm
2 string references to 'TaxoAdminForm'
File
- src/
Form/ TaxoAdminForm.php, line 12 - Contains Drupal\taxonomy_facets\Form\TaxoAdminForm.
Namespace
Drupal\taxonomy_facets\FormView source
class TaxoAdminForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'taxonomy_facets.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'taxonomy_facets_form';
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Retrieve the configuration
$config = \Drupal::configFactory()
->getEditable('taxonomy_facets.settings');
$config
->set('page_title', $form_state
->getValue('page_title'));
$config
->set('show_nodes_if_no_filters', $form_state
->getValue('show_nodes_if_no_filters'));
$config
->set('number_of_nodes_per_page', $form_state
->getValue('number_of_nodes_per_page'));
// Deal with vocabularies
$vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple();
foreach ($vocabularies as $vocabulary) {
$config
->set($vocabulary
->id(), $form_state
->getValue($vocabulary
->id()));
}
// Deal with content types
$contentTypes = \Drupal::service('entity.manager')
->getStorage('node_type')
->loadMultiple();
foreach ($contentTypes as $contentType) {
$config
->set('ct_' . $contentType
->id(), $form_state
->getValue('ct_' . $contentType
->id()));
}
$config
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TaxoAdminForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
TaxoAdminForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
TaxoAdminForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
TaxoAdminForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |