diff --git a/src/Plugin/facets/processor/TranslateEntityProcessor.php b/src/Plugin/facets/processor/TranslateEntityProcessor.php index 8bb17cb..60081b1 100644 --- a/src/Plugin/facets/processor/TranslateEntityProcessor.php +++ b/src/Plugin/facets/processor/TranslateEntityProcessor.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\Entity; use Drupal\Core\Form\FormStateInterface; use Drupal\facets\FacetInterface; +use Drupal\facets\Plugin\facets\facet_source\SearchApiViews; use Drupal\facets\Processor\BuildProcessorInterface; use Drupal\facets\Processor\ProcessorPluginBase; use Drupal\field\Entity\FieldStorageConfig; @@ -29,7 +30,6 @@ class TranslateEntityProcessor extends ProcessorPluginBase implements BuildProce */ public function build(FacetInterface $facet, array $results) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - $config = $this->getConfiguration(); $ids = []; /** @var \Drupal\facets\Result\ResultInterface $result */ @@ -37,8 +37,12 @@ class TranslateEntityProcessor extends ProcessorPluginBase implements BuildProce $ids[] = $result->getRawValue(); } + /** @var SearchApiViews $source */ + $source = $facet->getFacetSource(); + $field = $source->getIndex()->getField($facet->getFieldIdentifier()); + // Load the field config - $field_config = FieldStorageConfig::loadByName($config['entity_type'], $facet->getFieldIdentifier()); + $field_config = FieldStorageConfig::loadByName($field->getDatasource()->getEntityTypeId(), $facet->getFieldIdentifier()); // Load the indexed entities by using the target_type of the field config. $entities = \Drupal::entityTypeManager() ->getStorage($field_config->getSetting('target_type')) @@ -59,25 +63,4 @@ class TranslateEntityProcessor extends ProcessorPluginBase implements BuildProce return $results; } - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { - $form = parent::buildConfigurationForm($form, $form_state, $facet); - - $definitions = \Drupal::entityTypeManager()->getDefinitions(); - $entity_types = array_keys($definitions); - $config = $this->getConfiguration(); - - $form['entity_type'] = [ - '#type' => 'select', - '#title' => $this->t('Select the entity type, belonging to this field'), - '#options' => array_combine($entity_types, $entity_types), - '#default_value' => (isset($config['entity_type'])) ? $config['entity_type'] : NULL, - '#required' => TRUE - ]; - - return $form; - } - }