TaxonomyFacetsBlock1.php in Taxonomy Facets 8
File
src/Plugin/Block/TaxonomyFacetsBlock1.php
View source
<?php
namespace Drupal\taxonomy_facets\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormStateInterface;
class TaxonomyFacetsBlock1 extends BlockBase implements BlockPluginInterface {
public function build() {
$config = $this
->getConfiguration();
return [
'#markup' => taxonomy_facets_get_menu_tree($config['taxo_vocabulary_id']),
'#cache' => [
'max-age' => 0,
],
];
}
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this
->getConfiguration();
$form['vocab_select'] = [
'#type' => 'select',
'#title' => $this
->t('Select vocabulary. This block will display filters based on the taxonomy terms from the selected vocabulary'),
'#options' => taxonomy_vocabulary_get_names(),
'#default_value' => isset($config['taxo_vocabulary_id']) ? $config['taxo_vocabulary_id'] : '',
];
return $form;
}
public function blockSubmit($form, FormStateInterface $form_state) {
$this
->setConfigurationValue('taxo_vocabulary_id', $form_state
->getValue('vocab_select'));
}
}