public function Denormalize::buildConfigurationForm in Search API Grouping 8
Return the settings form for this processor.
Overrides FieldsProcessorPluginBase::buildConfigurationForm
File
- src/
Plugin/ search_api/ processor/ Denormalize.php, line 54
Class
- Denormalize
- This processor allows you to denormalize items.
Namespace
Drupal\search_api_grouping\Plugin\search_api\processorCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['permutation_limit'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Permutation limit'),
'#description' => t('Defines how permutations should be processed. Can become handy if you just want to have one item of a multi-value field. Leave empty for no limit.'),
'#weight' => 1,
];
$options = [];
foreach ($this
->getIndex()
->getFields() as $field_name => $field) {
$label = $field
->getLabel();
if (stristr($field_name, ':')) {
list($field_name, $property) = explode(':', $field_name, 2);
}
if (stristr($label, "»")) {
list($type, $label) = explode('»', $label, 2);
}
if ($field_info = FieldStorageConfig::loadByName('node', $field_name)) {
if (!empty($field_info
->getCardinality()) && ($field_info
->getCardinality() == -1 || $field_info
->getCardinality() > 1)) {
\Drupal::service('entity_field.manager')
->getBaseFieldDefinitions('node');
$options[$field_name] = $label . ' (' . $field_name . ')';
$form['permutation_limit'][$field_name] = [
'#type' => 'textfield',
'#title' => $label,
'#size' => 4,
'#maxlength' => 10,
'#states' => [
'visible' => [
':input[name$="[denormalization_field][' . $field_name . ']"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => !empty($this->configuration['permutation_limit'][$field_name]) ? $this->configuration['permutation_limit'][$field_name] : NULL,
];
}
}
}
$form['fields']['#options'] = $options;
// Re-use but modify the default form element.
$form['fields']['#type'] = 'checkboxes';
unset($form['fields']['#attributes']);
$form['denormalization_field'] = $form['fields'];
$form['fields']['#access'] = FALSE;
$form['denormalization_field'] = [
'#title' => t('The field to use to denormalize the items to index.'),
'#description' => t('The field hast to be selected for indexing to use it for denormalization.'),
'#default_value' => isset($this->configuration['denormalization_field']) ? $this->configuration['denormalization_field'] : NULL,
] + $form['denormalization_field'];
return $form;
}