public function GlossaryAZWidgetOrderProcessor::buildConfigurationForm in Search API AZ Glossary 8
Same name and namespace in other branches
- 8.4 src/Plugin/facets/processor/GlossaryAZWidgetOrderProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZWidgetOrderProcessor::buildConfigurationForm()
- 8.2 src/Plugin/facets/processor/GlossaryAZWidgetOrderProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZWidgetOrderProcessor::buildConfigurationForm()
- 8.3 src/Plugin/facets/processor/GlossaryAZWidgetOrderProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZWidgetOrderProcessor::buildConfigurationForm()
Adds a configuration form for this processor.
Parameters
array $form: The form.
\Drupal\Core\Form\FormStateInterface $form_state: The current form state.
\Drupal\facets\FacetInterface $facet: The facet this processor is being added to.
Overrides SortProcessorPluginBase::buildConfigurationForm
File
- src/
Plugin/ facets/ processor/ GlossaryAZWidgetOrderProcessor.php, line 121
Class
- GlossaryAZWidgetOrderProcessor
- A processor that orders the results by display value.
Namespace
Drupal\search_api_glossary\Plugin\facets\processorCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
$processors = $facet
->getProcessors();
$config = isset($processors[$this
->getPluginId()]) ? $processors[$this
->getPluginId()] : NULL;
// Get the weight options.
$sort_options = !is_null($config) ? $config
->getConfiguration()['sort'] : $this
->defaultConfiguration();
$sort_options_by_weight = $this
->sortConfigurationWeight($sort_options);
// Build the form.
$build['sort'] = array(
'#tree' => TRUE,
'#type' => 'table',
'#attributes' => array(
'id' => 'glossaryaz-sort-widget',
),
'#header' => array(
$this
->t('Sort By'),
$this
->t('Weight'),
),
'#tabledrag' => array(
array(
'action' => 'order',
'relationship' => 'sibling',
'group' => 'glossaryaz-sort-weight',
),
),
);
foreach ($sort_options_by_weight as $sort_option_key => $sort_option_weight) {
$build['sort'][$sort_option_key]['#attributes']['class'][] = 'draggable';
$build['sort'][$sort_option_key]['#attributes']['class'][] = 'glossaryaz-sort-weight--' . $sort_option_key;
$build['sort'][$sort_option_key]['#weight'] = $sort_option_weight;
$build['sort'][$sort_option_key]['sort_by']['#plain_text'] = $this
->defaultConfiguration()[$sort_option_key]['name'];
$build['sort'][$sort_option_key]['weight'] = array(
'#type' => 'weight',
'#delta' => count($this
->defaultConfiguration()),
'#default_value' => $sort_option_weight,
'#attributes' => array(
'class' => array(
'glossaryaz-sort-weight',
),
),
);
}
return $build;
}