diff --git a/src/Plugin/search_api/datasource/ContentEntity.php b/src/Plugin/search_api/datasource/ContentEntity.php index 1d44c6c..6c4133f 100644 --- a/src/Plugin/search_api/datasource/ContentEntity.php +++ b/src/Plugin/search_api/datasource/ContentEntity.php @@ -61,7 +61,7 @@ class ContentEntity extends DatasourcePluginBase { * * @var \Drupal\Core\Language\LanguageManagerInterface */ - protected $languageManger; + protected $languageManager; /** * {@inheritdoc} @@ -225,7 +225,7 @@ class ContentEntity extends DatasourcePluginBase { * The language manager. */ public function getLanguageManager() { - return $this->languageManger ?: \Drupal::getContainer()->get('language_manager'); + return $this->languageManager ?: \Drupal::languageManager(); } /** @@ -369,7 +369,7 @@ class ContentEntity extends DatasourcePluginBase { */ public function defaultConfiguration() { $default_configuration = array(); - if ($this->hasBundles() || $this->isTranslated()) { + if ($this->hasBundles() || $this->isTranslatable()) { $default_configuration['default'] = 1; } @@ -377,7 +377,7 @@ class ContentEntity extends DatasourcePluginBase { $default_configuration['bundles'] = array(); } - if ($this->isTranslated()) { + if ($this->isTranslatable()) { $default_configuration['languages'] = array(); } @@ -388,7 +388,7 @@ class ContentEntity extends DatasourcePluginBase { * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - if ($this->hasBundles() || $this->isTranslated()) { + if ($this->hasBundles() || $this->isTranslatable()) { $form['default'] = array( '#type' => 'radios', '#title' => $this->t('What should be indexed?'), @@ -412,7 +412,7 @@ class ContentEntity extends DatasourcePluginBase { ); } - if ($this->isTranslated()) { + if ($this->isTranslatable()) { $form['languages'] = array( '#type' => 'checkboxes', '#title' => $this->t('Languages'), @@ -523,7 +523,7 @@ class ContentEntity extends DatasourcePluginBase { } // Add language information in the description. - if ($this->isTranslated()) { + if ($this->isTranslatable()) { $languages = array_values(array_intersect_key($this->getLanguageManager()->getLanguages(), array_filter($this->configuration['languages']))); if ($this->configuration['default'] == TRUE) { $summary .= $this->t('Excluded languages: @languages', array('@languages' => implode(', ', $languages))); @@ -560,7 +560,7 @@ class ContentEntity extends DatasourcePluginBase { * @return bool * TRUE if the entity is translatable, FALSE otherwise. */ - protected function isTranslated() { + protected function isTranslatable() { return $this->getEntityType()->isTranslatable(); } @@ -615,7 +615,7 @@ class ContentEntity extends DatasourcePluginBase { $all_languages = $this->getLanguageManager()->getLanguages(); $configuration = $this->configuration; - if ($configuration['default'] == TRUE) { + if ($configuration['default']) { $allowed_languages = $all_languages; foreach ($configuration['languages'] as $langcode) { unset($allowed_languages[$langcode]); @@ -632,10 +632,9 @@ class ContentEntity extends DatasourcePluginBase { $item_ids = array(); /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ foreach ($this->getEntityStorage()->loadMultiple($entity_ids) as $entity_id => $entity) { - foreach (array_keys($entity->getTranslationLanguages()) as $langcode) { - if (array_key_exists($langcode, $allowed_languages)) { - $item_ids[] = "$entity_id:$langcode"; - } + $indexed_translations = array_intersect_key($entity->getTranslationLanguages(), $allowed_languages); + foreach (array_keys($indexed_translations) as $langcode) { + $item_ids[] = "$entity_id:$langcode"; } }