class SolrFieldTypeListBuilder in Search API Solr 4.x
Same name and namespace in other branches
- 8.3 src/Controller/SolrFieldTypeListBuilder.php \Drupal\search_api_solr\Controller\SolrFieldTypeListBuilder
- 8.2 src/Controller/SolrFieldTypeListBuilder.php \Drupal\search_api_solr\Controller\SolrFieldTypeListBuilder
Provides a listing of SolrFieldType.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\Core\Config\Entity\ConfigEntityListBuilder
- class \Drupal\search_api_solr\Controller\AbstractSolrEntityListBuilder uses BackendTrait
- class \Drupal\search_api_solr\Controller\SolrFieldTypeListBuilder
- class \Drupal\search_api_solr\Controller\AbstractSolrEntityListBuilder uses BackendTrait
- class \Drupal\Core\Config\Entity\ConfigEntityListBuilder
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of SolrFieldTypeListBuilder
File
- src/
Controller/ SolrFieldTypeListBuilder.php, line 13
Namespace
Drupal\search_api_solr\ControllerView source
class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header = [
'label' => $this
->t('Solr Field Type'),
'minimum_solr_version' => $this
->t('Minimum Solr Version'),
'managed_schema' => $this
->t('Managed Schema Required'),
'langcode' => $this
->t('Language'),
'domains' => $this
->t('Domains'),
'id' => $this
->t('Machine name'),
'enabled' => $this
->t('Enabled'),
];
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $solr_field_type) {
/** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */
$domains = $solr_field_type
->getDomains();
if (empty($domains)) {
$domains = [
'generic',
];
}
$enabled_label = $solr_field_type->disabledOnServer ? $this
->t('Disabled') : $this
->t('Enabled');
$enabled_icon = [
'#theme' => 'image',
'#uri' => !$solr_field_type->disabledOnServer ? 'core/misc/icons/73b355/check.svg' : 'core/misc/icons/e32700/error.svg',
'#width' => 18,
'#height' => 18,
'#alt' => $enabled_label,
'#title' => $enabled_label,
];
$row = [
'label' => $solr_field_type
->label(),
'minimum_solr_version' => $solr_field_type
->getMinimumSolrVersion(),
// @todo format
'managed_schema' => $solr_field_type
->requiresManagedSchema(),
// @todo format
'langcode' => $solr_field_type
->getFieldTypeLanguageCode(),
// @todo format
'domains' => implode(', ', $domains),
'id' => $solr_field_type
->id(),
'enabled' => [
'data' => $enabled_icon,
'class' => [
'checkbox',
],
],
];
return $row + parent::buildRow($solr_field_type);
}
/**
* {@inheritdoc}
*
* @throws \Drupal\search_api\SearchApiException
*/
public function load() {
static $entities;
$active_languages = array_keys(\Drupal::languageManager()
->getLanguages());
// Ignore region and variant of the locale string the langauge manager
// returns as we provide language fallbacks. For example, 'de' should be
// used for 'de-at' if there's no dedicated 'de-at' field type.
array_walk($active_languages, function (&$value) {
list($value, ) = explode('-', $value);
});
$active_languages[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
if (!$entities || $this->reset) {
$solr_version = '9999.0.0';
$operator = '>=';
$domain = 'generic';
$warning = FALSE;
$disabled_field_types = [];
try {
/** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
$backend = $this
->getBackend();
$disabled_field_types = $this
->getDisabledEntities();
$domain = $backend
->getDomain();
$solr_version = $backend
->getSolrConnector()
->getSolrVersion();
if (version_compare($solr_version, '0.0.0', '==')) {
$solr_version = '9999.0.0';
throw new SearchApiSolrException();
}
} catch (SearchApiSolrException $e) {
$operator = '<=';
$warning = TRUE;
}
// We need the whole list to work on.
$this->limit = FALSE;
$entity_ids = $this
->getEntityIds();
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
$storage = $this
->getStorage();
/** @var \Drupal\search_api_solr\Entity\SolrFieldType[] $entities */
$entities = $storage
->loadMultipleOverrideFree($entity_ids);
// We filter those field types that are relevant for the current server.
// There are multiple entities having the same field_type.name but
// different values for minimum_solr_version and domains.
$selection = [];
foreach ($entities as $key => $solr_field_type) {
$entities[$key]->disabledOnServer = in_array($solr_field_type
->id(), $disabled_field_types);
/** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */
$version = $solr_field_type
->getMinimumSolrVersion();
$domains = $solr_field_type
->getDomains();
list($language, ) = explode('-', $solr_field_type
->getFieldTypeLanguageCode());
if ($solr_field_type
->requiresManagedSchema() != $this
->getBackend()
->isManagedSchema() || version_compare($version, $solr_version, '>') || !in_array($language, $active_languages) || !in_array($domain, $domains) && !in_array('generic', $domains)) {
unset($entities[$key]);
}
else {
$name = $solr_field_type
->getFieldTypeName();
if (isset($selection[$name])) {
// The more specific domain has precedence over a newer version.
if ('generic' !== $domain && 'generic' === $selection[$name]['domain'] && in_array($domain, $domains) || version_compare($version, $selection[$name]['version'], $operator) && in_array($selection[$name]['domain'], $domains)) {
$this
->mergeFieldTypes($entities[$key], $entities[$selection[$name]['key']]);
unset($entities[$selection[$name]['key']]);
$selection[$name] = [
'version' => $version,
'key' => $key,
'domain' => in_array($domain, $domains) ? $domain : 'generic',
];
}
else {
$this
->mergeFieldTypes($entities[$selection[$name]['key']], $entities[$key]);
unset($entities[$key]);
}
}
else {
$selection[$name] = [
'version' => $version,
'key' => $key,
'domain' => in_array($domain, $domains) ? $domain : 'generic',
];
}
}
}
if ($warning) {
$this->assumedMinimumVersion = array_reduce($selection, function ($version, $item) {
if (version_compare($item['version'], $version, '<')) {
return $item['version'];
}
return $version;
}, $solr_version);
\Drupal::messenger()
->addWarning($this
->t('Unable to reach the Solr server (yet). Therefore the lowest supported Solr version %version is assumed. Once the connection works and the real Solr version could be detected it might be necessary to deploy an adjusted config to the server to get the best search results. If the server does not start using the downloadable config, you should edit the server and manually set the Solr version override temporarily that fits your server best and download the config again. But it is recommended to remove this override once the server is running.', [
'%version' => $this->assumedMinimumVersion,
]));
}
// Sort the entities using the entity class's sort() method.
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
uasort($entities, [
$this->entityType
->getClass(),
'sort',
]);
$this->reset = FALSE;
}
return $entities;
}
/**
* Returns a list of all disabled request handlers for current server.
*
* @return array
* A list of all disabled request handlers for current server.
*/
protected function getDisabledEntities() : array {
$backend = $this
->getBackend();
return $backend
->getDisabledFieldTypes();
}
/**
* Merge two Solr field type entities.
*
* @param \Drupal\search_api_solr\SolrFieldTypeInterface $target
* The target Solr field type entity.
* @param \Drupal\search_api_solr\SolrFieldTypeInterface $source
* The source Solr field type entity.
*/
protected function mergeFieldTypes(SolrFieldTypeInterface $target, SolrFieldTypeInterface $source) {
if (empty($target
->getCollatedFieldType()) && !empty($source
->getCollatedFieldType())) {
$target
->setCollatedFieldType($source
->getCollatedFieldType());
}
if (empty($target
->getSpellcheckFieldType()) && !empty($source
->getSpellcheckFieldType())) {
$target
->setSpellcheckFieldType($source
->getSpellcheckFieldType());
}
if (empty($target
->getUnstemmedFieldType()) && !empty($source
->getUnstemmedFieldType())) {
$target
->setUnstemmedFieldType($source
->getUnstemmedFieldType());
}
if (empty($target
->getSolrConfigs()) && !empty($source
->getSolrConfigs())) {
$target
->setSolrConfigs($source
->getSolrConfigs());
}
if (empty($target
->getTextFiles()) && !empty($source
->getTextFiles())) {
$target
->setTextFiles($source
->getTextFiles());
}
}
/**
* Returns the formatted XML for schema_extra_types.xml.
*
* @return string
* The XML snippet.
*
* @throws \Drupal\search_api\SearchApiException
*/
public function getSchemaExtraTypesXml() {
$xml = '';
/** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */
foreach ($this
->getEnabledEntities() as $solr_field_type) {
$xml .= $solr_field_type
->getAsXml();
$xml .= $solr_field_type
->getSpellcheckFieldTypeAsXml();
$xml .= $solr_field_type
->getCollatedFieldTypeAsXml();
$xml .= $solr_field_type
->getUnstemmedFieldTypeAsXml();
}
return $xml;
}
/**
* Returns the formatted XML for solrconfig_extra.xml.
*
* @param int|null $solr_major_version
*
* @return string
* The XML snippet.
*
* @throws \Drupal\search_api\SearchApiException
*/
public function getSchemaExtraFieldsXml(?int $solr_major_version = NULL) {
$xml = '';
/* @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */
foreach ($this
->getEnabledEntities() as $solr_field_type) {
foreach ($solr_field_type
->getStaticFields() as $static_field) {
$xml .= '<field ';
foreach ($static_field as $attribute => $value) {
/* @noinspection NestedTernaryOperatorInspection */
$xml .= $attribute . '="' . (is_bool($value) ? $value ? 'true' : 'false' : $value) . '" ';
}
$xml .= "/>\n";
}
foreach ($solr_field_type
->getDynamicFields($solr_major_version) as $dynamic_field) {
$xml .= '<dynamicField ';
foreach ($dynamic_field as $attribute => $value) {
/* @noinspection NestedTernaryOperatorInspection */
$xml .= $attribute . '="' . (is_bool($value) ? $value ? 'true' : 'false' : $value) . '" ';
}
$xml .= "/>\n";
}
foreach ($solr_field_type
->getCopyFields() as $copy_field) {
$xml .= '<copyField ';
foreach ($copy_field as $attribute => $value) {
/* @noinspection NestedTernaryOperatorInspection */
$xml .= $attribute . '="' . (is_bool($value) ? $value ? 'true' : 'false' : $value) . '" ';
}
$xml .= "/>\n";
}
}
return $xml;
}
/**
* Returns the formatted XML for solrconfig_extra.xml.
*
* @return string
* The XML snippet.
*
* @throws \Drupal\search_api\SearchApiException
*/
public function getSolrconfigExtraXml() {
$search_components = [];
/** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */
foreach ($this
->getEnabledEntities() as $solr_field_type) {
$xml = $solr_field_type
->getSolrConfigsAsXml();
if (preg_match_all('@(<searchComponent name="[^"]+"[^>]*?>)(.*?)</searchComponent>@sm', $xml, $matches)) {
foreach ($matches[1] as $key => $search_component) {
$search_components[$search_component][] = $matches[2][$key];
}
}
}
$xml = '';
foreach ($search_components as $search_component => $details) {
$xml .= $search_component;
foreach ($details as $detail) {
$xml .= $detail;
}
$xml .= "</searchComponent>\n";
}
return $xml;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractSolrEntityListBuilder:: |
protected | property | The default option. | |
AbstractSolrEntityListBuilder:: |
protected | property | The label. | 3 |
AbstractSolrEntityListBuilder:: |
protected | property |
The number of entities to list per page, or FALSE to list all entities. Overrides EntityListBuilder:: |
|
AbstractSolrEntityListBuilder:: |
protected | property | The option label. | |
AbstractSolrEntityListBuilder:: |
public | function | Get all not recommended entities. | |
AbstractSolrEntityListBuilder:: |
public | function | Get all recommended entities. | |
AbstractSolrEntityListBuilder:: |
public | function | Get all conflicting entities. | |
AbstractSolrEntityListBuilder:: |
public | function |
Overrides ConfigEntityListBuilder:: |
|
AbstractSolrEntityListBuilder:: |
public | function | Returns a list of all enabled Solr config entities for current server. | |
AbstractSolrEntityListBuilder:: |
public | function | Get all not recommended entities. | |
AbstractSolrEntityListBuilder:: |
public | function | Get all recommended Entities. | |
AbstractSolrEntityListBuilder:: |
public | function | Returns the formatted XML for the entities. | |
AbstractSolrEntityListBuilder:: |
protected | function | Merge two Solr config entities. | |
BackendTrait:: |
protected | property | The Solr minimum version string. | |
BackendTrait:: |
protected | property | The Search API server backend. | |
BackendTrait:: |
protected | property | Reset. | |
BackendTrait:: |
protected | property | The Search API server ID. | |
BackendTrait:: |
protected | function | Returns the Search API server backend. | |
BackendTrait:: |
public | function | Set assumed minimum version. | |
BackendTrait:: |
public | function | Sets the Search API server backend. | |
BackendTrait:: |
public | function | Sets the Search API server and calls setBackend() afterwards. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 5 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 5 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
EntityListBuilder:: |
protected | property | Information about the entity type. | |
EntityListBuilder:: |
protected | property | The entity type ID. | |
EntityListBuilder:: |
protected | property | The entity storage class. | 1 |
EntityListBuilder:: |
public | function | Builds a renderable list of operation links for the entity. | 2 |
EntityListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
20 |
EntityListBuilder:: |
protected | function | Ensures that a destination is present on the given URL. | |
EntityListBuilder:: |
protected | function | Loads entity IDs using a pager sorted by the entity id. | 4 |
EntityListBuilder:: |
public | function |
Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface:: |
2 |
EntityListBuilder:: |
public | function |
Gets the entity storage. Overrides EntityListBuilderInterface:: |
|
EntityListBuilder:: |
protected | function | Gets the title of the page. | 1 |
EntityListBuilder:: |
public | function |
Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilderInterface:: |
16 |
EntityListBuilder:: |
public | function | Constructs a new EntityListBuilder object. | 16 |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SolrFieldTypeListBuilder:: |
public | function |
Builds the header row for the entity listing. Overrides AbstractSolrEntityListBuilder:: |
|
SolrFieldTypeListBuilder:: |
public | function |
Builds a row for an entity in the entity listing. Overrides AbstractSolrEntityListBuilder:: |
|
SolrFieldTypeListBuilder:: |
protected | function |
Returns a list of all disabled request handlers for current server. Overrides AbstractSolrEntityListBuilder:: |
|
SolrFieldTypeListBuilder:: |
public | function | Returns the formatted XML for solrconfig_extra.xml. | |
SolrFieldTypeListBuilder:: |
public | function | Returns the formatted XML for schema_extra_types.xml. | |
SolrFieldTypeListBuilder:: |
public | function | Returns the formatted XML for solrconfig_extra.xml. | |
SolrFieldTypeListBuilder:: |
public | function |
Overrides AbstractSolrEntityListBuilder:: |
|
SolrFieldTypeListBuilder:: |
protected | function | Merge two Solr field type entities. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |