You are here

class TaxoAdminForm in Taxonomy Facets 8

Hierarchy

Expanded class hierarchy of TaxoAdminForm

2 string references to 'TaxoAdminForm'
taxonomy_facets.routing.yml in ./taxonomy_facets.routing.yml
taxonomy_facets.routing.yml
taxonomy_facets.routing.yml in ./taxonomy_facets.routing.yml
taxonomy_facets.routing.yml

File

src/Form/TaxoAdminForm.php, line 12
Contains Drupal\taxonomy_facets\Form\TaxoAdminForm.

Namespace

Drupal\taxonomy_facets\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TaxoAdminForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
TaxoAdminForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
TaxoAdminForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
TaxoAdminForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.